Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers 2

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.