-3

I have log file for checking transactions, and I have error lines, so I need those error lines to be exported to a .csv file? is there any code using linux bash shell script can do this?

HKLM
  • 41
  • 7
  • 1
    The short answer is: yes. The long answer is: it depends. – Red Cricket Feb 11 '19 at 03:36
  • Hi Red Cricket! So what it mean it depends? – HKLM Feb 11 '19 at 03:40
  • 1
    It depends on a lot of details you have left out of your question. – Red Cricket Feb 11 '19 at 03:41
  • @RedCricket , the log files have thousands of lines, usually I'm using filezilla to download the file from remote linux server then open it using notepad plus plus, then find all lines that contains error lines, copy them and paste them to an xls then save as csv file to be send by email to the vendors? – HKLM Feb 11 '19 at 03:45
  • I need to automate the above process. – HKLM Feb 11 '19 at 03:45
  • 2
    Post sample data, expected output and show some work done. – James Brown Feb 11 '19 at 03:48
  • 1
    If you could, **without disclosing any sensitive information**, post some of the lines from the log file. – Red Cricket Feb 11 '19 at 03:58
  • Hard to answer without more information. Google `grep`. – Keldorn Feb 11 '19 at 04:18
  • @JamesBrown & I have added more details as above. hope that helps – HKLM Feb 11 '19 at 15:53
  • @RedCricket I have added more details now, may be it helps. – HKLM Feb 11 '19 at 15:54
  • In order for us to help you script some kind of solution for log processing, we need some sample data, like lines from your log—not full lines but with the columns what are needed to decide whether the line is an error line or not—positive and negative samples with the expected output. Otherwise I'll say that `grep "error" log` you'll say that it won't say `error` but `unable to`and the file is not named `log` etc. And for testing they need to be in text. Would you start out helping someone by copying the data from an image to a file? – James Brown Feb 11 '19 at 16:13

1 Answers1

0

suppose your error lines consists ERROR. then

grep "ERROR" errorfile.txt | tr -s '[:blank:]' ',' >> errorfile.csv

csv conversion is based on blank spaces to each cell.you can replace blank filter with anything

Akhil
  • 912
  • 12
  • 23
  • 2
    You will want to avoid the [useless use of `cat`.](/questions/11710552/useless-use-of-cat) The temporary file is also easy to avoid. – tripleee Feb 11 '19 at 06:16
  • i used cat for easy understanding.thank you for your useful comment on useless use of cat – Akhil Feb 11 '19 at 06:20
  • @ AkhilJalagam, Thanks for your resolution, I think I'm fine with that, and do you know for any script that make this csv file to be sent to an email, as a daily base, like can we make a script that make this csv file attached to an email daily ? – HKLM Feb 11 '19 at 16:17
  • yes , you can ```sendemail -f sender@some.where -t receiver@some.place -m "Here are your files!" -a errorfile.csv``` – Akhil Feb 12 '19 at 05:48
  • @AkhilJalagam, It worked, thanks. but I was asking if you could give more examples for blank, so I dont need each blank to be comma (,), only for specific fields, can we do that,so for my case I need blank before "error" string to be in comma. – HKLM Feb 20 '19 at 18:49
  • yes , you can. in that case you have to use ```awk```. @HKLM – Akhil Feb 21 '19 at 07:48
  • How I could use awk for that? so for example for the above, I need the results to be exported to csv without delimited commas! @AkhilJalagam – HKLM Feb 25 '19 at 20:51