Sunday, 4 May 2014

How to pass out put of a command as an argument to another command ?

How to pass out put of a command as an argument to another command ?
Ans-
xargs is a very powerful command that takes output of a command and pass it as argument of another command.
ex-
 [root@localhost dir2]# pwd
/tmp/dir2
[root@localhost dir2]# ls
[root@localhost dir2]# echo "file1" >> test.txt
[root@localhost dir2]# echo "file2" >> test.txt

[root@localhost dir2]# cat test.txt
file1
file2
[root@localhost dir2]# ls
test.txt
[root@localhost dir2]# cat test.txt | xargs touch
[root@localhost dir2]# ls
file1  file2  test.txt

No comments:

Prasanta Kumar Behera. Mob- 8147470101