LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices



Reply
 
Search this Thread
Old 01-28-2004, 09:08 PM   #1
Bassam
Member
 
Registered: Mar 2003
Location: Malaysia
Posts: 63

Rep: Reputation: 15
Question 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
 
Old 01-28-2004, 09:51 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,590

Rep: Reputation: 188Reputation: 188
"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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script to Delete line if pattern exists topcat Programming 22 08-23-2011 05:58 AM
unix shell script:How to delete the first line in a file?? rche3252 Programming 6 03-03-2010 08:32 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 08:15 PM
Delete line from flat text file in C zaichik Programming 6 01-26-2005 07:16 PM
Shell script - how to show a specific line of a text file davi_cabral Linux - Software 3 09-28-2004 02:39 PM


All times are GMT -5. The time now is 09:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration