Advertisement
Guest User

Untitled

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