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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SED remove pathlike string from file

Status
Not open for further replies.

UsRb

IS-IT--Management
Mar 19, 2007
48
HR
Hi2all,

if I have string "/mbu/data/cms" and I want to delete line that contains that string, I would do following:

variable i is automatically created from another file:
$i=/mbu/data/cms

sed "/$i/d" file

Ouput is "sed: 0602-410 The first regular expression cannot be null." because of slashes (/). How can I tell sed this is the complete string?
 
I'm using Korn shell.

Problem is I cannot define variable myself, it is defined from another file while reading it.

 

First code doesn't work, I'm on AIX.

I've managed to combine your second code in my script.

Thank you
 
I don't think you are restricted to just using "/" as the delimeter. Try "!" or "?". As in:

sed "!$i!d" file


I hope that helps.

Mike
 
Sorry, perhaps I should have tested it properly before making the suggestion. How about this for an idea?

$i1=`echo $i | sed 's!/!.!g'` # ie replace all "/" with "."
sed "/$i1/d" file


I hope that helps.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top