I have some troubles removing the string between the first space \s and the first tab \t of a text file (the tab should be kept):

sample input:

col1_frame1 unimportant    a b    c

expected output for sample:

col1_frame    a b    c

I tried with sed 's/ .*\t/\t/' but I got a wrong output:

my output for sample (using previous sed):

col1_frame    c

1 Answer 1


It's because .* will match to anything (as it is the regular expression wildcard) and can and will then be expanded as much as possible until the last tab seen (and encompassing any other tabs in between). What you want is [^\t]* which will match any string not containing a tab, so combined your call to sed should look like this: sed 's/ [^\t]*\t/\t/'

You must log in to answer this question.

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