Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > General
User Name
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!


  Search this Thread
Old 01-28-2004, 08:08 PM   #1
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:

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

Thanks for your support in advance

Old 01-28-2004, 08:51 PM   #2
LQ Guru
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Jessie, Linux Mint 17
Posts: 7,734

Rep: Reputation: 262Reputation: 262Reputation: 262
"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 "/" client_ip_addresses)

Be prepared. Create a LifeBoat CD.

Steve Stites


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 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

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

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