Delete all charactere before DPT_p_



  • Hello,

    I have a lot of lines and i want to delete all caractere before DPT_p_EXT_CONTACT.deliv and delete “.deliv”
    -rw-rw-r-- 1 pstambia pstambia 131721 Apr 9 2018 DPT_p_EXT_CONTRACT.deliv
    -rw-rw-r-- 1 pstambia pstambia 122364 Nov 28 22:56 DPT_p_EXT_CRC.deliv
    -rw-rw-r-- 1 pstambia pstambia 137893 Apr 9 2018 DPT_p_EXT_CRENGLOG.deliv
    -rw-r–r-- 1 pstambia pstambia 120692 Oct 29 09:36 DPT_p_EXT_COLLQ4.deliv
    -rw-r–r-- 1 pstambia pstambia 118732 Oct 29 09:36 DPT_p_EXT_COLLQ5B.deliv

    Finaly i want to keep only -rw-rw-r-- 1 pstambia pstambia 131721 Apr 9 2018 DPT_p_EXT_CONTRACT.deliv
    DPT_p_EXT_CRC
    DPT_p_EXT_CRENGLOG
    DPT_p_EXT_COLLQ4
    DPT_p_EXT_COLLQ5B

    Thanks in advance :)



  • @Juliana-Mialoundama

    I didn’t try it (AFK…ATM) but maybe something like this?:

    Find (?-is)^.*?(DPT_P_EXT_.*?)\.deliv
    Replace \1
    Search mode Regular expression



  • @Alan-Kilborn: with case-sensitive (?-is), the p would have be lower case in your find-what: (?-is)^.*?(DPT_p_EXT_.*?)\.deliv

    @Juliana-Mialoundama: your description is slightly self-contradictory. You say you want to delete everything before “DPT_p_EXT_CONTRACT”, and delete the .deliv after, but then in your example “results” data, the only line that wasn’t modified was the line with “CONTRACT”.

    With the example data

    -rw-rw-r-- 1 pstambia pstambia 131721 Apr 9 2018 DPT_p_EXT_CONTRACT.deliv
    -rw-rw-r-- 1 pstambia pstambia 122364 Nov 28 22:56 DPT_p_EXT_CRC.deliv
    -rw-rw-r-- 1 pstambia pstambia 137893 Apr 9 2018 DPT_p_EXT_CRENGLOG.deliv
    -rw-r--r-- 1 pstambia pstambia 120692 Oct 29 09:36 DPT_p_EXT_COLLQ4.deliv
    -rw-r--r-- 1 pstambia pstambia 118732 Oct 29 09:36 DPT_p_EXT_COLLQ5B.deliv
    

    you showed an output of

    -rw-rw-r-- 1 pstambia pstambia 131721 Apr 9 2018 DPT_p_EXT_CONTRACT.deliv
    DPT_p_EXT_CRC
    DPT_p_EXT_CRENGLOG
    DPT_p_EXT_COLLQ4
    DPT_p_EXT_COLLQ5B
    

    If what you really meant was “I want to delete everything but the base filename, deleting all the text before the filename and deleting the .deliv extension”, then my modified versoin of Alan’s find-what (?-is)^.*?(DPT_p_EXT_.*?)\.deliv should work for you:

    DPT_p_EXT_CONTRACT
    DPT_p_EXT_CRC
    DPT_p_EXT_CRENGLOG
    DPT_p_EXT_COLLQ4
    DPT_p_EXT_COLLQ5B
    

    If that’s not what you meant, please include an actual representation of the example input and example output. The forum will edit your post for you if you don’t tell it that it’s code/preformatted text. To quote myself:

    See @Scott-Sumner’s “help with Markdown in this forum” post, and my recent followup at the end of that thread, for how to embed an example file: you can watch the PREVIEW-pane to the right of the COMPOSE-pain when typing your reply, to see how the forum will format the post; try to fix it so it properly displays the data you are posting. There are two important aspects: 1) we need the data that we see to accurately reflect your data: the data you posted appears to have smart quotes, and I am guessing you meant those to be normal quotes, but that’s only a guess. By following the formatting advice in the post I just directed you to, we will be more certain that the data we are seeing matches what data you actually have. 2) The data needs to accurately reflect the possible variations in your data that need to match (and if there will be lines that don’t need to match, we need to know that too, so that it won’t accidentally match what it’s supposed to.). However, you do NOT have to show all 891 lines. Just show a few matching lines, and a few lines that don’t match – making sure that you’ve shown a reasonable variety, and clearly indicated matches vs non-matches.

    -----

    FYI: if you have further search-and-replace (regex) needs, study this FAQ and the documentation it points to. Before asking a new regex question, understand that for future requests, many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backward to get things working for you. If you need help formatting the data so that the forum doesn’t mangle it (so that it shows “exactly”, as I said earlier), see this help-with-markdown post, where @Scott-Sumner gives a great summary of how to use Markdown for this forum’s needs.
    Please note that for all “regex” queries – or queries where you want help “matching” or “marking” or “bookmarking” a certain pattern, which amounts to the same thing – it is best if you are explicit about what needs to match, and what shouldn’t match, and have multiple examples of both in your example dataset. Often, what shouldn’t match helps define the regular expression as much or more than what should match.

    -----



  • ps: sorry, my first

    See @Scott-Sumner’s “help with Markdown in this forum”

    should have been

    See @Scott-Sumner’s “help with Markdown in this forum”

    I copied/pasted from the rendered rather than the source, so the link disappeared.

    The link was there below in my FYI section, but I wanted to make it clear.


Log in to reply