biotech
biotech

Reputation: 727

Replace a string with sed script

Input:

Proc Natl Acad Sci U S A. 2014 May 27;111(21):7819-24. doi: 10.1073/pnas.1400586111. Epub 2014 May 13.

Desired output:

Proc Natl Acad Sci U S A. 2014 May 27;111(21):7819-24.

What I tried:

sed 's/doi: *//' 

Upvotes: 1

Views: 15

Answers (1)

Wintermute
Wintermute

Reputation: 44073

Use

sed 's/doi: .*//' 

In the pattern you tried, the * applies to the space before it, so doi: followed by an arbitrary number of spaces is removed, and what comes after that remains.

.*, by contrast, matches an arbitrary number of arbitrary characters (because . in a regex matches any character), and doi: .* matches doi: followed by a space and then all characters until the end of the line.

Upvotes: 1

Related Questions