Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "data":{"headers":{"sender":"frank@abc.com"
- "to":"jim@def.com"
- "subject":"Help with this project"
- "x-received-time":"14144273245408"
- "received":"from abc.com ()rn by mail.mail.com with SMTP (Postfix)rn for jim@def.com;rn Mon
- "from":""Help with this project" <frank@abc.com>"
- "date":"Mon, 27 Oct 2014 09:03:14 -0500"
- "id":"1414427328-2345855-frank"
- "to":"jim@def.com"
- "time":14144273245408
- "subject":"Help with this project"
- "fromfull":"frank@abc.com"
- perl -n0e '@a= $_ =~ /"date":(".*?").*?"id":(".*?").*?"to":"(.*?)".*?".*?"subject":(".*?").*?"fromfull":"(.*?)"/gs; while (my @next_n = splice @a, 0, 5) { print join(q{,}, @next_n)."n"}' inputfile.txt
- "Mon, 27 Oct 2014 09:03:14 -0500","1414427328-2345855-frank",jim@def.com,"Help with this project",frank@abc.com
- jq '.data.headers | [.sender, .to, .subject, ."x-received-time",
- .received, .from, .date, .id, .to, .subject, .fromfull]
- + [(.time | tostring)] | join(", ")'
- node parseline.js < some.txt
- node parsefile.js yourfile.json > yourfile.csv
- #!/usr/bin/gawk -f
- BEGIN {
- FS="""
- output=""
- nodata=1
- }
- /^"data"/{
- if( ! nodata )
- {
- gsub("|$","",output)
- print output
- nodata=0
- }
- output=""
- }
- /^"[^d][^a][^t][^a]/{
- if ( $2 == "to" || $2 == "fromfull" || $2 == "id" || $2 == "subject" || $2 == "date" )
- output=output$4"|"
- }
- END{
- gsub("|$","",output)
- print output
- }
- awk -F ":" '{gsub(""","",$1);key=$1;sub(key " ","");gsub("\","",$0);value[key]=$0; if ("fromfull"== key) print value["from"] ";" value["to"] ";" value["fromfull"] ";" value["id"] ";" value["subject"] ";" value["date"] ;}' jsonFile > csvFile
- ""Help with this project" <frank@abc.com>";"jim@def.com";"frank@abc.com";"1414427328-2345855-frank";"Help with this project";"Mon, 27 Oct 2014 09 03 14 -0500"
- cat YOUR_JSON_FILEname | jsonv to,fromfull,id,subject,date > output.csv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement