Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. A^_B^_C
  2. AA^_BB^_CC
  3.  
  4. wc -L file
  5.  
  6. awk '
  7. {
  8. for(i=1;i<=NF;i++)
  9. if (length($i) == good) { continue }
  10. else {
  11. print "Row "NR" contained data more than " good" in a single field"
  12. next
  13. }
  14. print "Row "NR " is valid"
  15. }' FS='\^_' good="1" csv
  16. Row 1 is valid
  17. Row 2 contained data more than 1 in a single field
  18.  
  19. awk -F'\^_' -v OFS=':' '
  20. {
  21. for (i=1;i<=NF;i++) {
  22. if (length($i) > max) {
  23. max = length($i)
  24. lineNr = NR
  25. line = $0
  26. fldNr = i
  27. fld = $i
  28. }
  29. }
  30. }
  31. END {
  32. print lineNr, line
  33. print fldNr, fld
  34. }
  35. ' file
  36.  
  37. 1^_1^_1
  38.  
  39. awk -F'\^_' '
  40.  
  41. NR==FNR {split($0,clen,FS); next} # store the lengths
  42.  
  43. {
  44. split($0,a,FS); # put the current line in an array
  45. for( i in a )
  46. { if( length(a[i]) > clen[i] ) print "["FNR","i"] = "a[i] }
  47. }
  48. ' clengths data
  49.  
  50. [2,1] = AA
  51. [2,2] = BB
  52. [2,3] = CC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement