SHARE
TWEET

Untitled

a guest Jun 25th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. A -> Y
  2. B -> V
  3. C -> Q
  4. ...
  5.      
  6. ABCDEFGHIJ
  7.      
  8. sed -i 's/A/Y/;s/B/V/' file
  9.      
  10. sed 's/A/Y/' file > file1; sed 's/B/V/' file > file1
  11.      
  12. $ cat sub.txt
  13. A -> Y
  14. B -> V
  15. C -> Q
  16. D -> K
  17. E -> L
  18. F -> O
  19. G -> P
  20. H -> W
  21. I -> X
  22. J -> Z
  23.      
  24. while read from a to; do ... ; done < sub.txt
  25.      
  26. while read from a to; do
  27.     tr "$from" "$to" <<<"$string" > changed."$from".txt
  28. done < sub.txt
  29.      
  30. $ ls changed*
  31. changed.A.txt  changed.D.txt  changed.G.txt  changed.J.txt
  32. changed.B.txt  changed.E.txt  changed.H.txt
  33. changed.C.txt  changed.F.txt  changed.I.txt
  34.      
  35. $ for f in changed.*; do echo "=== $f ==="; cat $f; done
  36. === changed.A.txt ===
  37. YBCDEFGHIJ
  38. === changed.B.txt ===
  39. AVCDEFGHIJ
  40. === changed.C.txt ===
  41. ABQDEFGHIJ
  42. === changed.D.txt ===
  43. ABCKEFGHIJ
  44. === changed.E.txt ===
  45. ABCDLFGHIJ
  46. === changed.F.txt ===
  47. ABCDEOGHIJ
  48. === changed.G.txt ===
  49. ABCDEFPHIJ
  50. === changed.H.txt ===
  51. ABCDEFGWIJ
  52. === changed.I.txt ===
  53. ABCDEFGHXJ
  54. === changed.J.txt ===
  55. ABCDEFGHIZ
  56.      
  57. tmpFile=$(mktemp)
  58. echo "$string" > "$tmpFile"
  59. while read from a to; do
  60.     tr "$from" "$to" < "$tmpFile" > changed."$from".txt
  61.     cp changed."$from".txt "$tmpFile"
  62. done < sub.txt
  63.      
  64. $ for f in changed.*; do echo "=== $f ==="; cat $f; done
  65. === changed.A.txt ===
  66. YBCDEFGHIJ
  67. === changed.B.txt ===
  68. YVCDEFGHIJ
  69. === changed.C.txt ===
  70. YVQDEFGHIJ
  71. === changed.D.txt ===
  72. YVQKEFGHIJ
  73. === changed.E.txt ===
  74. YVQKLFGHIJ
  75. === changed.F.txt ===
  76. YVQKLOGHIJ
  77. === changed.G.txt ===
  78. YVQKLOPHIJ
  79. === changed.H.txt ===
  80. YVQKLOPWIJ
  81. === changed.I.txt ===
  82. YVQKLOPWXJ
  83. === changed.J.txt ===
  84. YVQKLOPWXZ
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top