Oracle-Unix commands: Pipe operator and xargs command. [message #60219] |
Sun, 25 January 2004 23:18 |
Patrick Tahiri
Messages: 119 Registered: January 2004
|
Senior Member |
|
|
Hi,
I would like to know what is the difference between the pipe operator and the xargs command?!
xargs command is used to pipe a list to another command but so does the pipe (|) operator?
Many thanks for your help!
Regards,
Patrick Tahiri.
|
|
|
Re: Oracle-Unix commands: Pipe operator and xargs command. [message #60224 is a reply to message #60219] |
Mon, 26 January 2004 06:16 |
Thiru
Messages: 1089 Registered: May 2002
|
Senior Member |
|
|
Hi
pipe and xargs serve different functions.
pipe simply passes in the o/p of one command as i/p to the 2nd command(ie o/p one program becomes the i/p of the subsequent program through the pipe).
xargs ,on the other hand,constructs an argument list based on the o/p of the 1st command, that can be used on the 2nd command.
Both are used in conjunction. For eg)
dbatest@samgdeab06:/ora1/oracle>ls test*
test test.out test.sql test.tar
# Here sort takes in the o/p of the preceeding command and acts on it to give us the sorted o/p. This happens becos of the pipe
dbatest@samgdeab06:/ora1/oracle>ls test*|sort
test
test.out
test.sql
test.tar
# In the following example, ls cannot take in the i/p from it's standard in. So it just lists out the whole directory, irrespective of the standard i/p.
dbatest@samgdeab06:/ora1/oracle>ls test*|ls
1 doc oui test.out
NOT dsmerror.log product test.sql
afiedt.buf email spcpkg.lis test.tar
app findExec spctab.lis tmp
daily_checklist_space.log jre spcusr.lis
dbadmin ls.out sppurge.lis
dead.letter oraInventory test
# This is where xargs serves us. As you see below,xargs takes the standard i/p, constructs an arguement list and passes that as 'arguements' to the 'ls' command. And 'ls' works on those arguments and gives us the result.
dbatest@samgdeab06:/ora1/oracle>ls test*|xargs ls
test test.out test.sql test.tar
# As seen below, when used with -i option, xargs replaces {} with the i/p arguements. the test* files are moved to the directory TEST
dbatest@samgdeab06:/ora1/oracle>ls test*|xargs -i mv {} TEST
dbatest@samgdeab06:/ora1/oracle>ls TEST
test test.out test.sql test.tar
-Thiru
|
|
|
|