Quick answer to post #1 is to not use exec or cat.
Please remember to post what Operating System you have and what Shell you use.
I've got error here:
The -name pattern argument needs to be quoted.
Quote:
Originally Posted by Tribe
Quote:
Originally Posted by 244an
Here is a solution near your own code:
But I think some of the already given answers is the best, like that with using xargs as an example.
That solution doesn't specify to which file belongs each line, but is shorter after all.
To enable the printing of filenames without otherwise altering the results, you can add /dev/null to grep's list of files to process, e.g., -exec grep PATTERN {} /dev/null \;.
Regards,
Alister
These 2 Users Gave Thanks to alister For This Post:
For me it was an interesting thread, not considering the "best" solution I learned some new things.
Quote:
Originally Posted by alister
...
To enable the printing of filenames without otherwise altering the results, you can add /dev/null to grep's list of files to process, e.g., -exec grep PATTERN {} /dev/null \;.
Using /dev/null that way was good to know (I also noticed now that alister was meaning the solution I suggested in his first post).
And good to learn the use of ... | while read file; do ...; done in
Quote:
Originally Posted by methyl
...
And finally using xargs
Quote:
Originally Posted by Tribe
...
But I have a question to the xargs-solution, why is this printing filenames? Is xargs using grep (in the example) as with grep file1 file2 fil3 ... ? I thought that the used construction with find ... -print | xargs grep ... would do one grep for each file, not one grep with all files.
Anyone understands my question?
For me it was an interesting thread, not considering the "best" solution I learned some new things.
Using /dev/null that way was good to know (I also noticed now that alister was meaning the solution I suggested in his first post).
And good to learn the use of ... | while read file; do ...; done in
And finally using xargs
But I have a question to the xargs-solution, why is this printing filenames? Is xargs using grep (in the example) as with grep file1 file2 fil3 ... ? I thought that the used construction with find ... -print | xargs grep ... would do one grep for each file, not one grep with all files.
Anyone understands my question?
In this case, xargs executes the grep command only once , because the file1, file2, etc you say don't exist, just the standard input that is a block of data. It is grep that detects inside the stream what are the files.
You can see here:
While the -exec runs the command once per found item:
------------------------------------
In fact, I made a mistake using -print instead of -print0, because if there is a filename with spaces or other odd characters will cause error.
Results in binary comparison:
So -print and -print0 for find are not equal. The same option has to be used with xargs to prevents errors.
i have perl script that used to be working great , once i edit it in windows
and convert it to UTF-8 and then via FTP return it .
also did:
chmod +x foo.pl
and then when i try to run it :
./foo.pl
im getting this error:
./foo.pl: Exec format error. Wrong Architecture.... (4 Replies)
Guys,
I want to find the log files greather than 23 days and i want to perform 2 things here.
one is to list the files and second is to gzip the files. hope this can be done using sh -c option. but not sure the exact command.
find . -name "*.log" -mtime +23 -exec ls -la {} \;
... (5 Replies)
Hi Friends,
Please help me to sort out this problem, I am running this in centos o/s and whenever I run this script I am getting "find: missing argument to `-exec' " but when I run the same code in the command line I didn't find any problem. I am using perl script to run this ... (2 Replies)
This is a huge issue. and I need it fixed ASAP.
account-system gate-system race_traffic_sensor
achievement-system global race_voicepack
admin glue-system realdriveby
admin-system gps realism-system... (5 Replies)
Hello,
I am a linux newbe. I want to install a program. I can download it only with wget command from internet.
As far as i know this wget command does not transfer the exacutable flags.
Because of that i wanted to find all configure files and change their mod to 744.
I found this... (1 Reply)
Hello All,
Is there a way to make exec do a couple of operations on a single input from find?
For example,
find . -type d -exec ls -l "{}" ";"
I would like to give the result of each "ls -l" in the above to a wc. Is that possible?
I want to ls -l | wc -l inside... (1 Reply)
Hi,
i would like to rename files in directories and subdirs.
Files contains specific french or strange caracters.
I want to replace all non alpha-numerics by _ (underscore)
First, i made this, but i think the "for" is limited.
How can i do this directly by FIND ?
for file in $(find .... (0 Replies)
can we use |(pipe operator) with find -exec.....?
or can pipe the output of find command to another command...?
if not, why...?
pls explain (3 Replies)
Hi,
I am trying to run the following command:
find ./ -name lea_01.001 -print -exec CEOS {} | grep -i radio \;
where "CEOS" converts the lea_01.001 files to text, then grep looks for the string "radio." This however does not work as I have constructed it.
This command mostly works, but... (1 Reply)
Hi,
Happy new year.
Would you be so kind to explain me what does this instruction :
find /rep/app -type l -exec ls -l {} \;> allink.lst
Many thanks. (2 Replies)