Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-14-2011, 12:21 PM   #1
Registered: Sep 2011
Posts: 46

Rep: Reputation: Disabled
Question command to find and delete line in single shot.

i have a file in solaris. In which i want to delete line whenever it find "able to delete" sentence at single shot. Is there any awk command or some command to satisfy my need.

i have to delete this line
i am not able to DELETE this line
i am not able to DE LETE this line
able TO delete this line
finding the command.
Old 11-14-2011, 12:56 PM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960
sed is probably the best tool to use here. Deleting a line containing a set pattern is an easy thing to do with it.

Here are a few useful sed references.

Recognize that the version of sed you use on solaris likely has some differences to the gnu sed used on Linux. gnu has added a lot of features like the -i edit in place option that yours probably won't have.

It's generally better if you have some knowledge of regular expressions too.

grep -v is another possible option.
Old 11-14-2011, 01:02 PM   #3
Senior Member
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
You can do that with a combination of find, grep, sed and a little shell program (you do use KornShell, right?).
#       look for files, grep for "able to delete" and delete the line if so
for file in $(find your_path -type f)
        if [ ! grep -q "able to delete" ]
                sed '/able to delete/d' ${file} > /tmp/junk
                mv /tmp/junk ${file}
If you want to display a bunch of messages, just add appropriate print blah in there.

Hope this helps some.
1 members found this post helpful.
Old 11-14-2011, 01:27 PM   #4
Registered: Sep 2011
Posts: 46

Original Poster
Rep: Reputation: Disabled
Thank you its working fine for me.


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
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 07:19 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 04:45 PM
LXer: fdupes - Command line tool to find and list/delete duplicate files LXer Syndicated Linux News 0 10-28-2008 03:40 PM
Help me in Grep Command + cd command in single line JeiPrakash Linux - Newbie 3 05-27-2008 04:16 AM
a single command the spans more then 1 line bourne Programming 4 11-27-2007 05:50 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:42 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