My current code is:
user@ubuntu:~/Desktop$ grep -e "\(packaged by\)\|\(employee\)\|\(file name\)\|\(Total Data (MB) Read\)\|\(Begin Time\)" log.txt
packaged by = Ron Mexico
employee = Michael Vick
file name = Mike_Vick_2011.bat
Total Data (MB) Read: 11.82
Begin Time: 6/13/2011 10:29:27 AM
How can I get the output to be:
Ron Mexico
Michael Vick
Mike_Vick_2011.bat
11.82
6/13/2011 10:29:27 AM
$ grep -e "\(packaged by\)\|\(employee\)\|\(file name\)\|\(Total Data (MB) Read\)\|\(Begin Time\)" log.txt|awk -F"=" '{print $2}'
1 Like
awk -F"=" '{print $2}'
This works, but I also have ":" in the logs. Any way to combine "=" and ":"?
Thanks for the quick response.
use it like
awk -F"[:=]" '{print $2}'
1 Like
The date stamp gets jacked up because it removes the ":" in the time.
6/13/2011 10
Is it possible to do something like:
awk -F"[:=]" '{print $2,":",print $3,":",print $4}'
Please post the input data and the required output.
user@ubuntu:~/Desktop$ grep -e "\(packaged by\)\|\(employee\)\|\(file name\)\|\(Total Data (MB) Read\)\|\(Begin Time\)" log.txt
packaged by = Ron Mexico
employee = Michael Vick
file name = Mike_Vick_2011.bat
Total Data (MB) Read: 11.82
Begin Time: 6/13/2011 10:29:27 AM
Output should be:
Ron Mexico
Michael Vick
Mike_Vick_2011.bat
11.82
6/13/2011 10:29:27 AM
If you have the time, I'm really trying to get the output into a CSV, so the output should be:
"Ron Mexico","Michael Vick","Mike_Vick_2011.bat","11.82","6/13/2011 10:29:27 AM"
$ awk -F"[:=]" '{if($0~/Time/){printf("\"%s:%s:%s\"\n",$2,$3,$4)}else{printf("\"%s\",",$2)}}' test.txt
" Ron Mexico"," Michael Vick"," Mike_Vick_2011.bat"," 11.82"," 6/13/2011 10:29:27 AM"
---------- Post updated at 08:39 PM ---------- Previous update was at 08:31 PM ----------
you dont need to use grep and pipe this awk. You can try the below.
awk -F"[:=]" ' /packaged by/ || /employee/ || /file name/ || /Total Data/|| /Begin Time/ {if($0~/Time/){printf("\"%s:%s:%s\"\n",$2,$3,$4)}else{printf("\"%s\",",$2)}}' log.txt
How do you remove the space after any "="?
Something like?
awk -F"[':' '= ']"
---------- Post updated at 01:42 PM ---------- Previous update was at 01:21 PM ----------
Is this going to work for all files in a directory?
This will parse the first file, but not work on other log files in the directory:
awk -F"[:=]" ' /packaged by/ || /employee/ || /file name/ || /Total Data/|| /Begin Time/ {if($0~/Time/){printf("\"%s:%s:%s\"\n",$2,$3,$4)}else{printf("\"%s\",",$2)}}' /path/to/*