1

After using a filter to get a list of process like the next one:

FOO_AAAAA_00001
FOO_BBBBB_00001
FOO_ABABAB_0000
FOO_ABCCDAA_00
FOO_12345678_0
FOO_JJJ_00001
FOO_VLLLL_00001
FOO_KKAKAA_00001

The string is cut when the lenght excedes a certain number. I need to change the last part of the name of the process for another script that uses that name. The problem is that names ends in 00001 .

I have tried something like

[...]|sed 's/000/00001/g[...]

but the problem is obvious. It changes the correct strings too. My question is, there's a way to be able to use sed to make the change correctly when the chain is 0,00,000 to 0001 without altering the other ones?

Let's supose i have the above list:

FOO_AAAAA_00001
FOO_BBBBB_00001
FOO_ABABAB_0000
FOO_ABCCDAA_00
FOO_12345678_0
FOO_JJJ_00001
FOO_VLLLL_00001
FOO_KKAKAA_00001

First and last ones are correct. I need to get something like :

FOO_AAAAA_00001
FOO_BBBBB_00001
FOO_ABABAB_00001
FOO_ABCCDAA_00001
FOO_12345678_00001
FOO_JJJ_00001
FOO_VLLLL_00001
FOO_KKAKAA_00001

Thanks

  • Please paste example output: it isn't entirely clear what you want to achieve... – jasonwryan Feb 13 '16 at 5:59
  • Edited There's a example of what i am looking for. – Jesus Cepeda Feb 13 '16 at 6:08
1

Finally

virt01@virt01:~$ sed 's/_0*$/_00001/g' some.txt
somestring_oooo_00001
somestring_oooo_00001
somestring_oooo_00001
virt01@virt01:~$

Exactly for your data

virt01@virt01:~$ cat some.txt
FOO_AAAAA_00001
FOO_BBBBB_00001
FOO_ABABAB_0000
FOO_ABCCDAA_00
FOO_12345678_0
FOO_JJJ_00001
FOO_VLLLL_00001
FOO_KKAKAA_00001
virt01@virt01:~$ sed 's/_0*$/_00001/g' some.txt
FOO_AAAAA_00001
FOO_BBBBB_00001
FOO_ABABAB_00001
FOO_ABCCDAA_00001
FOO_12345678_00001
FOO_JJJ_00001
FOO_VLLLL_00001
FOO_KKAKAA_00001
virt01@virt01:~$
  • Not worked. Need to change all the 0s lower than 4 to 0000 and add 1 to the end: 0->0001 ; 00->0001; 000->0001 – Jesus Cepeda Feb 13 '16 at 6:11
  • @JesusCepeda Its working . I updated my answer – rɑːdʒɑ Feb 13 '16 at 6:21
2

This will substitute the third occurrence in pattern-space of the longest possible match for 0 or more not-underscore characters for the string 00001.

 sed 's/[^_]*/00001/3' <in >out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.