1

I have a file with thousands of lines that start with:

>Miriam132_38138    Otu32555|1

I need to remove 'Miriam*********' so that each lines begins with:

>Otu32555|1

The first string of characters is always a combination of the word 'Miriam' and a set of 7, 8, or 9 characters. I played around with sed without much success.

1
  • <stuff><whitespace><stuff>? awk is your friend here.
    – Ricky
    May 13, 2015 at 5:18

5 Answers 5

1

If you want to remove first "word" from the line you can use something like

awk '{print $2}' input.txt

assuming you have whitespace between "words"

0
0

Assuming that the set of 7-9 characters ends with a space, and that Miriam is on the line only once:

sed 's/\(.*\)Miriam.* /\1/' input.txt

The \(.*\) part "saves" the pattern matched before Miriam and puts it back in with \1

0
sed '/^Miriam/s/[^ ]* *//' <in >out

...will do. It will remove from any line which opens with the string Miriam only the first sequence of not-space characters followed by the first string of space characters. It will not affect any line which does not open with that string and it will not remove any but the first occurrence of said string.

0

Use this,

awk '{print $2}' filename > outputfile  

It should definitely work. It will print the second word of each lines in file and output will be save in the file named "outputfile"

-1

Use awk:

awk '{print substr($0, index($0, $2))}' file

Removes just the first field, but prints all other fields.

Or sed:

sed 's/Miriam132_38138 \+//' file

If the > at the start of the line should be preserved, that removes just the first match.

You must log in to answer this question.

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