LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 08: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, 08:51 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,340

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



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 04:58 AM
unix shell script:How to delete the first line in a file?? rche3252 Programming 6 03-03-2010 07:32 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
Delete line from flat text file in C zaichik Programming 6 01-26-2005 06:16 PM
Shell script - how to show a specific line of a text file davi_cabral Linux - Software 3 09-28-2004 01:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 09:02 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
Open Source Consulting | Domain Registration