Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


#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

#cat newfile.csv

#----My requirement output is:

cat newfile.csv

Kind regards, please help me if anyone knowns

share|improve this question

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

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
man cut... sounds painful. – Matt Fletcher Oct 17 '14 at 13:12

Your Answer


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.