LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (http://www.linuxquestions.org/questions/general-10/)
-   -   How to delete a line from a text file with shell script programming (http://www.linuxquestions.org/questions/general-10/how-to-delete-a-line-from-a-text-file-with-shell-script-programming-139785/)

Bassam 01-28-2004 08:08 PM

How to delete a line from a text file with shell script programming
 
Hi All,
In my shell script programming, I created a text file that contains a number of records, and I want to delete a specific line after after locating it.
I am using the sed instruction to find the line number of the record that I want to delete it, but actually I don't know what commnd should I use to do it.

Take Note: I want to shift up all the records inside my file after deleting a specific record some where in the middle.

My sed command to locate the line no. is:

Quote:

LI_NO=$(sed -n "/192.168.8.1/=" client_ip_addresses)
and my text file "client_ip_addresses" contains the following records:

192.168.170.2
200.10.18.30
100.100.150.40
.
.
.
200.192.168.4


Thanks for your support in advance

Regards
Bassam

jailbait 01-28-2004 08:51 PM

"I want to delete a specific line after after locating it. "

sed will delete a line of text with the d command. I am not sure how to work the syntax into your existing command. This is my first stab at it.

LI_NO=$(sed "/192.168.8.1/d" client_ip_addresses)

___________________________________
Be prepared. Create a LifeBoat CD.
http://users.rcn.com/srstites/LifeBo...home.page.html

Steve Stites


All times are GMT -5. The time now is 11:10 PM.