LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 09-13-2009, 10:43 AM   #1
xpto09
LQ Newbie
 
Registered: Oct 2007
Posts: 18

Rep: Reputation: 0
How to put in one line this sed command?


diff -u 1arq 2arq > 3arq
sed -i '/word/!d' 3arq
sed -i -n '/+/p' 3arq
sed -i 's/^.\{1\}//' 3arq
sed -i '/^$/d' 3arq

I want to put all the commands in one line.
 
Old 09-13-2009, 10:48 AM   #2
neddie_seagoon
LQ Newbie
 
Registered: Sep 2009
Distribution: Arch Linux
Posts: 1

Rep: Reputation: 0
You should be able to pipe the output of each command into the next:
diff -u 1arq 2arq | sed '/word/!d' | sed -n '/+/p' | sed 's/^.\{1\}//' | sed '/^$/d' > 3arq
 
Old 09-13-2009, 11:49 AM   #3
xpto09
LQ Newbie
 
Registered: Oct 2007
Posts: 18

Original Poster
Rep: Reputation: 0
Code:
diff -u 1arq 2arq | sed '/word/!d' | sed -n '/+/p' | sed 's/^.\{1\}//' | sed '/^$/d' > 3arq
What I really want is to create one COMMAND with all seds commands.
Like this:
sed '/AAA/!d; /BBB/!d; /CCC/!d'
or
sed '/AAA.*BBB.*CCC/!d'
or
sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d
 
Old 09-13-2009, 12:30 PM   #4
sploot
Member
 
Registered: Sep 2009
Location: Phoenix, AZ
Distribution: Gentoo, Debian, Ubuntu
Posts: 121

Rep: Reputation: 27
Quote:
Originally Posted by xpto09 View Post
diff -u 1arq 2arq > 3arq
sed -i '/word/!d' 3arq
sed -i -n '/+/p' 3arq
sed -i 's/^.\{1\}//' 3arq
sed -i '/^$/d' 3arq

I want to put all the commands in one line.
This can be performed by placing all the subsequent commands inside the quote separated by semicolons.
ie. sed -i '/word/!d; s/^&.\{1}//; /^$/d' 3arq

I don't think this will work if you are actually changing the sed operation like you want to do between the first and second, and again between second and third operations.

Alternatively, you could continue by running something like:

sed -i '/word/!d' -i -n '/+/p' -i 's/^.\{1\}//' -i '/^$/d'

Good luck!
--Sploot

Last edited by sploot; 09-13-2009 at 12:32 PM.
 
Old 09-13-2009, 12:50 PM   #5
xpto09
LQ Newbie
 
Registered: Oct 2007
Posts: 18

Original Poster
Rep: Reputation: 0
sed -i '/word/!d' -i -n '/+/p' -i 's/^.\{1\}//' -i '/^$/d' 3arq
sed: can't read /+/p: No such file or directory
sed: can't read s/^.\{1\}//: No such file or directory
sed: can't read /^$/d: No such file or directory
 
Old 09-13-2009, 01:05 PM   #6
sploot
Member
 
Registered: Sep 2009
Location: Phoenix, AZ
Distribution: Gentoo, Debian, Ubuntu
Posts: 121

Rep: Reputation: 27
Sorry, what I meant was something more like this:

sed -i -n -e '/word/!d' -e '/+/p' -e 's/^.\{1\}//' -e '/^$/d'

I know this functions properly with simple uses of sed (which means what I understand of it. Switching strings and such.) and I think it would work here, but I wouldn't swear by it.

--Sploot
 
  


Reply

Tags
sed


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
trying to output only first line of command out put dave247 Debian 2 11-03-2008 04:36 PM
Put a date/time from the command line Jzarecta Linux - Software 1 10-03-2007 12:48 PM
sed / awk command to print line number as column? johnpaulodonnell Linux - Newbie 2 01-22-2007 07:07 AM
Getting last characters of a line with sed command LULUSNATCH Programming 4 12-21-2005 09:33 AM
Sed Command : Line Start with benjagol Linux - Newbie 2 05-31-2005 02:28 AM


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

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