tags:

views:

70

answers:

1

Hey

I'm having hard time selecting from a file using a regular expression. I'm trying to replace a specific text in the file which is full of lines like this.

/home/user/test2/data/train/train38.wav /home/user/test2/data/train/train38.mfc

I'm trying to replace the bolded text. The problem is the i don't know how to select only the bolded text since i need to use .wav in my regexp and the filename and the location of the file is also going to be different.

Hope you can help

Best regards, Jökull

A: 

This assumes that what you want to replace is the string between the last two slashes in the first path.

sed 's|\([^/]*/\)[^/]*\(/[^/]* .*\)|\1FOO\2|' filename

produces:

/home/user/test2/data/FOO/train38.wav /home/user/test2/data/train/train38.mfc
Dennis Williamson