Advertisement
Guest User

Untitled

a guest
Oct 9th, 2017
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. "data":{"headers":{"sender":"[email protected]"
  2. "subject":"Help with this project"
  3. "x-received-time":"14144273245408"
  4. "received":"from abc.com ()rn by mail.mail.com with SMTP (Postfix)rn for [email protected];rn Mon
  5. "from":""Help with this project" <[email protected]>"
  6. "date":"Mon, 27 Oct 2014 09:03:14 -0500"
  7. "id":"1414427328-2345855-frank"
  8. "time":14144273245408
  9. "subject":"Help with this project"
  10. "fromfull":"[email protected]"
  11.  
  12. 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
  13.  
  14. "Mon, 27 Oct 2014 09:03:14 -0500","1414427328-2345855-frank",[email protected],"Help with this project",[email protected]
  15.  
  16. jq '.data.headers | [.sender, .to, .subject, ."x-received-time",
  17. .received, .from, .date, .id, .to, .subject, .fromfull]
  18. + [(.time | tostring)] | join(", ")'
  19.  
  20. node parseline.js < some.txt
  21.  
  22. node parsefile.js yourfile.json > yourfile.csv
  23.  
  24. #!/usr/bin/gawk -f
  25. BEGIN {
  26. FS="""
  27. output=""
  28. nodata=1
  29. }
  30.  
  31. /^"data"/{
  32. if( ! nodata )
  33. {
  34. gsub("|$","",output)
  35. print output
  36. nodata=0
  37. }
  38. output=""
  39. }
  40.  
  41. /^"[^d][^a][^t][^a]/{
  42. if ( $2 == "to" || $2 == "fromfull" || $2 == "id" || $2 == "subject" || $2 == "date" )
  43. output=output$4"|"
  44. }
  45.  
  46. END{
  47. gsub("|$","",output)
  48. print output
  49. }
  50.  
  51. 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
  52.  
  53. ""Help with this project" <[email protected]>";"[email protected]";"[email protected]";"1414427328-2345855-frank";"Help with this project";"Mon, 27 Oct 2014 09 03 14 -0500"
  54.  
  55. cat YOUR_JSON_FILEname | jsonv to,fromfull,id,subject,date > output.csv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement