Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete a line based on a pattern 1

Status
Not open for further replies.

mrimagepueblo

Programmer
Dec 15, 2003
52
US
I have a tab delimited file where one field has multiple entries seperated by a pipe |.
ie.
field1 field2 field3 123|239|234| field5

what I want to do is match on the |239 and delete that line out of the file.
I am running a bash shell script and have tried this line and thought it would work.
perl -pi -e 's/\|239/d' listings-residential.txt
but I get an error:
Substitution replacement not terminated at -e line 1.
I also tried
perl -pi -e 's/|239/d' listings-residential.txt
and get the same error.
I even get the same error with
perl -pi -e 's/239/d' listings-residential.txt
So is the /d' not valid this way?
What am I missing? Would an awk statement be better since I know that if the match occurs it's in field 4 of the data file? It's possible that |239 could occur in other fields.


 
And what about something like this ?
sed '/\|239/d' listings-residential.txt > newfile.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Feherke, thanks your perl solution worked like a charm. It's late/early in the am for me. I'll look up the command you gave me to figure out why it worked.
Thanks a bunch.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top