Home Ask Login Register

Developers Planet

Your answer is one click away!

gorilon February 2016

Sed substitution with back reference not working

I receive output from a program as tab separated values, of which I am trying to obtain the second only using sed. I am currently using this:

sed -r -e "s/(^[^\t]+\t)([^\t]+\t)(.*$)/\2/"

However it does not seem to find matches. I have tried it in rubular were it does give me the match I want.

enter image description here


Lars Fischer February 2016

There is a specialized tool for selecting columns from text files called cut:

cut -f2 file

Here we instruct it to select only the second column, see the manpage for more information. Tab is the default column separator.

Post Status

Asked in February 2016
Viewed 1,670 times
Voted 9
Answered 1 times


Leave an answer

Quote of the day: live life