I'm trying to concatenate all the files of a that ends with coref extension.
This works (but add unwanted files):
find ../corpus/dev/txt/ | xargs cat
This not works.
find ../corpus/dev/txt/ -name '*.coref' | xargs cat
In the second comand find returns 1566 results but xrags cat does nothing.
Why the -name arguments mess it all?
Try to use -print0 like this:
find ../corpus/dev/txt/ -name '*.coref' -print0 | xargs -0 cat
if you find to many files and the xargs list gets too long, you can try this:
find ../corpus/dev/txt/ -name '*.coref' -print0 | xargs -n1 -0 cat >> /tmp/file
Related
I am trying to create a script which looks for x days old files that have a specific string in it, it then removes it and logs the file it has changed.
My way is probably not the best way, but I am new to this so looking for some help. I have got to a stage where the script works but it does not log the file name it has worked on
Working script is
find /home/test -mtime +5 -type f ! -size 0 | xargs grep -E -l '(abc_Pswd_[1-9])' | xargs -n1 sed -i '/abc_Pswd_[1-9].*/d'
I am trying to get the file name from 2nd part of the script I have tried few things
find /home/test -mtime +7 -type f ! -size 0 | xargs grep -E -l '(abc.1x.[1-9] )' > /home/test/tst.log| xargs -n1 sed -i '/abc_Pswd_[1-9].*/d'
This works in terms of logging the result but it exits with the error "sed: no input files"
$ echo "file_contents" > filename.txt
$ find . -type f -print0 | xargs -0 sed 's/file//g'
_contents
How do you get sed to treat the filename as a string instead of an input file? What command do I need to get "name.txt" as the output instead?
Drop the xargs and -0's.
find . -type f | sed 's/file//g'
This takes the output of find and sends it as input to sed.
I would like to check the 'code rating' for each Python file in a directory. The name of the file and its rating should be printed.
I thought the following would at least print all code ratings:
find . -name '*.py' -print0 | xargs -0 pylint | grep "has been rated"
However, it prints only one code rating. Why? How do I fix it?
Try:
find . -name '*.py' -exec pylint {} \; | grep "has been rated"
I'm using executing this bash commands inside a search script I've built with php:
find myFolder -type f -exec grep -r KEYWORD {} +
find myFolder -type f -exec grep -r KEYWORD {} + | wc -l
find myFolder -type f | wc -l
The first line gives me back the filenames where KEYWORD was found.
The second line gives me the number of occurrences and the third line the total number of files.
Is there a way to do this more elegantly and faster?
You can get more efficiency if you avoid -exec, which makes one fork per file match. xargs is a better choice here. So I would do something like this:
find myFolder -type f -print0 | xargs -0 grep KEYWORD
find myFolder -type f -print0 | xargs -0 grep KEYWORD | wc -l
The last one should be OK, at least with GNU find.
The -print0 and -0 ensure that filenames with spaces in them are handled correctly.
Note that grep -r` implies recursive grepping, but as you're only supplying one filename in each invocation it is redundant.
I use following find command to find and show all files having the input text pattern.
find . -type f -print|xargs grep -n "pattern"
I have many project folders each of which has its own makefile named as 'Makefile'.(no file extension, just 'Makefile')
How do i use above command to search for a certain pattern only in the files named Makefile which are present in all my project folders?
-AD.
-print is not required (at least by GNU find implementation). -name argument allows to specify filename pattern. Hence the command would be:
find . -name Makefile | xargs grep pattern
If you have spaces or odd characters in your directory paths youll need to use the null-terminated method:
find . -name Makefile -print0 | xargs -0 grep pattern
find . -type f -name 'Makefile' | xargs egrep -n "pattern"
use egrep if you have very long paths
Duplicate of : this
You can avoid the use of xargs by using -exec:
find . -type f -name 'Makefile' -exec egrep -Hn "pattern" {} \;
-H on egrep to output the full path to the matching files.
grep -R "string" /path
Please find this link
http://rulariteducation.blogspot.in/2016/03/how-to-check-particluar-string-in-linux.html
you can use ff command i.e ff -p .format. For eg ff -p *.txt
Find big files occupying large disk space
we need to combine multiple command .
find . -type f | xargs du -sk | sort -n | tail;