LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 11-14-2011, 01:21 PM   #1
Sha_unix
Member
 
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.

file:
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, 01: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: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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.
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/grabbag/
http://sed.sourceforge.net/sedfaq.html
http://sed.sourceforge.net/sed1line.txt

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, 02:02 PM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,479

Rep: Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020
You can do that with a combination of find, grep, sed and a little shell program (you do use KornShell, right?).
Code:
#!/bin/ksh
#
#       look for files, grep for "able to delete" and delete the line if so
#
for file in $(find your_path -type f)
do
        if [ ! grep -q "able to delete" ]
        then
                sed '/able to delete/d' ${file} > /tmp/junk
                mv /tmp/junk ${file}
        fi
done
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, 02:27 PM   #4
Sha_unix
Member
 
Registered: Sep 2011
Posts: 46

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


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


All times are GMT -5. The time now is 02:21 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration