KianStar
KianStar

Reputation: 177

How to remove a special string from a file?

Im trying to remove the following two lines:

<STREAMINFO> 1 39
<VECSIZE> 39<NULLD><MFCC_D_A_0><DIAGC>

which are repeated many times in a texfile (hmmdefs) in the folder hmm0.

How could I do that in UNUX?

Tried to remove each time separately, but when running the following command in command-line:

sed "<STREAMINFO> 1 39" hmm0/hmmdefs

I receive the following error:

sed: 1: "<STREAMINFO> 1 39": invalid command code <

Upvotes: 0

Views: 45

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174844

You need to use d flag to delete the line which was matched by the given regex. And don't forget to enclose the regex within the / delimiters.

sed "/<STREAMINFO> 1 39/d" hmm0/hmmdefs

To be more specific, you need to add anchors.

sed "/^<STREAMINFO> 1 39$/d" hmm0/hmmdefs

^ Asserts that we are at the start and $ asserts that we are at the end.

Example:

$ cat file
<STREAMINFO> 1 39
<VECSIZE> 39<NULLD><MFCC_D_A_0><DIAGC>
foo bar
$ sed '/<STREAMINFO> 1 39\|<VECSIZE> 39<NULLD><MFCC_D_A_0><DIAGC>/d' file
foo bar

Upvotes: 1

Related Questions