LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to put in one line this sed command? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-put-in-one-line-this-sed-command-754826/)

xpto09 09-13-2009 11:43 AM

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.

neddie_seagoon 09-13-2009 11:48 AM

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

xpto09 09-13-2009 12:49 PM

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

sploot 09-13-2009 01:30 PM

Quote:

Originally Posted by xpto09 (Post 3681035)
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

xpto09 09-13-2009 01:50 PM

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

sploot 09-13-2009 02:05 PM

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


All times are GMT -5. The time now is 09:03 PM.