Guest User

Untitled

a guest
Dec 11th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. test1,test2,test3
  2. test4,test5
  3. test6,test7,test8,test9,test10
  4. test11,test12,test13,test14
  5.  
  6. test1,test2;test3
  7. test4,test5
  8. test6,test7;test8;test9;test10
  9. test11,test12;test13;test14
  10.  
  11. $ sed 's/,/n/g; s/n/,/; s/n/;/g' input
  12. test1,test2;test3
  13. test4,test5
  14. test6,test7;test8;test9;test10
  15. test11,test12;test13;test14
  16.  
  17. $ sed -e 's/,/;/g' -e 's/;/,/1' infile
  18. test1,test2;test3
  19. test4,test5
  20. test6,test7;test8;test9;test10
  21. test11,test12;test13;test14
  22.  
  23. sed 's/,/;/2g' infile
  24.  
  25. awk '{gsub(",", ";"); sub(";", ","); print}' file.txt
  26.  
  27. % cat file.txt
  28. test1,test2,test3
  29. test4,test5
  30. test6,test7,test8,test9,test10
  31. test11,test12,test13,test14
  32.  
  33. % awk '{gsub(",", ";"); sub(";", ","); print}' file.txt
  34. test1,test2;test3
  35. test4,test5
  36. test6,test7;test8;test9;test10
  37. test11,test12;test13;test14
  38.  
  39. txr -e '(each ((line (get-lines)))
  40. (set [line (rest (where (op eql #,) line))]
  41. (repeat ";"))
  42. (put-line line))' < input
  43.  
  44. $ txr
  45. This is the TXR Lisp interactive listener of TXR 148.
  46. Use the :quit command or type Ctrl-D on empty line to exit.
  47.  
  48. 1> (take 3 (repeat ";"))
  49. (#; #; #;)
  50.  
  51. 2> (let ((a "a,b,c"))
  52. a)
  53. "a,b,c"
  54.  
  55. 3> (let ((a "a,b,c"))
  56. [a '(1 3)])
  57. ",,"
  58.  
  59. 4> (let ((a "a,b,c"))
  60. (where (op eql #,) a))
  61. (1 3)
  62.  
  63. 5> (let ((a "a,b,c"))
  64. (set [a '(1 3)] (repeat ";"))
  65. a)
  66. "a;b;c"
  67.  
  68. 6> (let ((a "a,b,c"))
  69. (set [a (where (op eql #,) a)] (repeat ";"))
  70. a)
  71. "a;b;c"
  72.  
  73. 7> (let ((a "a,b,c"))
  74. (set [a (rest (where (op eql #,) a))] (repeat ";"))
  75. a)
  76. "a,b;c"
  77.  
  78. 8> (let ((a ""))
  79. (set [a (rest (where (op eql #,) a))] (repeat ";"))
  80. a)
  81. ** replace-str: "" of type lit is not a modifiable string
  82. ** during evaluation of form (sys:dwim-set a #:g0145 #:g0144)
  83. ** ... an expansion at expr-8:2 of (sys:dwim-set (#:g0146) #:g0145
  84. #:g0144)
  85. ** which is located at expr-8:2
  86.  
  87. 9> (let ((a (copy "")))
  88. (set [a (rest (where (op eql #,) a))] (repeat ";"))
  89. a)
  90. ""
  91.  
  92. 10> (let ((a "a"))
  93. (set [a (rest (where (op eql #,) a))] (repeat ";"))
  94. a)
  95. "a"
  96.  
  97. 11> (let ((a "a,b"))
  98. (set [a (rest (where (op eql #,) a))] (repeat ";"))
  99. a)
  100. "a,b"
Add Comment
Please, Sign In to add comment