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

2
  • Please paste example output: it isn't entirely clear what you want to achieve... Commented Feb 13, 2016 at 5:59
  • Edited There's a example of what i am looking for. Commented Feb 13, 2016 at 6:08

2 Answers 2

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
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:~$
2
  • 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 Commented Feb 13, 2016 at 6:11
  • @JesusCepeda Its working . I updated my answer Commented Feb 13, 2016 at 6:21

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.