7

I have a bunch of files with lots of rows configured like this:

what,r-crq,What,What,VAC5700-035080,What
i,pns11,I,I,VAC5700-035090,I
do,vdd,did,did,VAC5700-035100,did

I want to do a search and replace to end up with this, storing and reinserting the 4 numbers after VAC and removing the trailing portion of the VAC number:

what,r-crq,What,What,VAC5700,What
i,pns11,I,I,VAC5700,I
do,vdd,did,did,VAC5700,did

Is there a way to do this for all the files at once (the VAC number will vary, so it needs to be stored as a variable), preferably in the Bash shell?

I assume I could also do this in “Notepad++” using regex, but I think the shell script would be preferable as I could do all the files as a batch.

1
  • You say, "the VAC number will vary, so it needs to be stored as a variable".  I don't understand.  I suspect that you're overthinking this — Steven's answer should do what you want.  (And, if it does, you should accept it.)  But, if his answer doesn't work for you, that suggests that you haven't explained your problem completely, correctly, and clearly. Oct 17, 2015 at 7:30

1 Answer 1

7

Use the sed command:

sed -e 's|,VAC\([0-9][0-9][0-9][0-9]\)-[0-9]*,|,VAC\1,|' inFile > outFile

It will substitute ,VAC####-#...#, with ,VAC####,.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .