grep "something" anyfiles.log > afile.csv , don't need to print the input path and file name to CSV file
I have some logs files, they have more than 30000 lines. I need to find the name "domain" and save in CSV file but after saving, any lines in CSV file has been added the path and file name of input files at the beginning of very line of CSV file. How can I do if I don't need the path and input file name add to CSV files.
Example:
Input
#cat /home/log/any.log
any things..domain, anything
any things..domain, anything
any things..domain, anything
grep "domain" /home/logs/any.log > newfile.csv
Output:
#cat newfile.csv
/home/logs/any.log:domain
/home/logs/any.log:domain
/home/logs/any.log:domain
#----My requirement output is:
cat newfile.csv
domain
domain
domain
Kind regards, please help me if anyone knowns
Use the --no-filename
option for grep.
Suppress the prefixing of file names on output. This is the default when there is only one file (or only standard input) to search.
grep --no-filename "domain"
Reference: Grep Manual
See man cut
for details, but the short answer is grep "domain" /home/logs/*.log | cut -d: -f2 >newfile.csv
.
Or see man grep
and do grep -o "domain" /home/logs/*.log >newfile.csv
PS: grep does NOT output the filename if there's only ONE file on the command line, like grep "domain" /home/logs/any.log
in your example. If you want to force filenames to be output, grep "domain" /home/logs/any.log /dev/null
will do the trick.