XARGS Madness
4 posters
XARGS Madness
Have been trying to understand the working of xargs for quite sometime now.Can someone help me understand and give me some sample code that will help me practise.
The following is what I have tried but could not get the output
find <directory name> - name "*.txt" -print | xargs grep <pattern> | tee <file_name>
The following is what I have tried but could not get the output
find <directory name> - name "*.txt" -print | xargs grep <pattern> | tee <file_name>
Nazneennazim- Posts : 10
Points : 16
Join date : 2010-03-01
Re: XARGS Madness
this is a simple program
the output of the command preceding is passed line by line to the command following xargs
[335802@oracleclient ~]$ cat>datadata
data1
data2
[1]+ Stopped cat > datadata
[335802@oracleclient ~]$ cat>data1
data1
hello1
[2]+ Stopped cat > data1
[335802@oracleclient ~]$ cat>data2
data2
hello2
[3]+ Stopped cat > data2
[335802@oracleclient ~]$ cat datadata | xargs cat
data1
hello1
data2
hello2
the output of the command preceding is passed line by line to the command following xargs
[335802@oracleclient ~]$ cat>datadata
data1
data2
[1]+ Stopped cat > datadata
[335802@oracleclient ~]$ cat>data1
data1
hello1
[2]+ Stopped cat > data1
[335802@oracleclient ~]$ cat>data2
data2
hello2
[3]+ Stopped cat > data2
[335802@oracleclient ~]$ cat datadata | xargs cat
data1
hello1
data2
hello2
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Re: XARGS Madness
For example, take this example
- Code:
ls *.txt | xargs cat
Re: XARGS Madness
find <directory name> - name "*.txt" -print
the above line lists all the .txt files in that particular directory.
| symbol passes the output of the above code to the command on the right
xargs grep <pattern>
in this xargs does the job of taking in multiple arguements(which is actually a list) and performs the grep function
the above line lists all the .txt files in that particular directory.
| symbol passes the output of the above code to the command on the right
xargs grep <pattern>
in this xargs does the job of taking in multiple arguements(which is actually a list) and performs the grep function
jeeva- Posts : 50
Points : 93
Join date : 2010-03-04
Re: XARGS Madness
[335802@oracleclient ~]$ cat>y.txt
12345
34567
[5]+ Stopped cat > y.txt
[335802@oracleclient ~]$ cat>y1.txt
123
abc
def
[6]+ Stopped cat > y1.txt
[335802@oracleclient ~]$ cat>y12.txt
andfff
dfree
[7]+ Stopped cat > y12.txt
[335802@oracleclient ~]$ find ./ -name "y*" -type f -print | xargs grep "123tee hg.txt
./y.txt:12345
./y1.txt:123
[335802@oracleclient ~]$ find ./ -name "y*" -type f -print | xargs grep "a" e hg.txt
./y12.txt:andfff
./y1.txt:abc
12345
34567
[5]+ Stopped cat > y.txt
[335802@oracleclient ~]$ cat>y1.txt
123
abc
def
[6]+ Stopped cat > y1.txt
[335802@oracleclient ~]$ cat>y12.txt
andfff
dfree
[7]+ Stopped cat > y12.txt
[335802@oracleclient ~]$ find ./ -name "y*" -type f -print | xargs grep "123tee hg.txt
./y.txt:12345
./y1.txt:123
[335802@oracleclient ~]$ find ./ -name "y*" -type f -print | xargs grep "a" e hg.txt
./y12.txt:andfff
./y1.txt:abc
akalya- Posts : 70
Points : 86
Join date : 2010-03-04
Permissions in this forum:
You cannot reply to topics in this forum
|
|