TEXT 27
Paste.txt Guest on 6th September 2020 05:40:47 PM
  1. ------------------------------------------------------------------------
  2. paste
  3. ------------------------------------------------------------------------
  4. summary:
  5. paste allows you to put two files "side by side". In contrast cat lets you put
  6. one file below another. As with cat the two files need NOT be of equal length.
  7.  
  8. paste options file1 file2 ..
  9.  
  10. options: all are optional
  11.  -d  --delimiter (only one character; but see below for "feature") [tab]
  12.  -s  --serial
  13.  
  14.  
  15.  
  16. $ seq 1 3 > a  
  17. $ seq 4 1 6 > b
  18.  
  19. $ paste a b
  20. 1       4       #default delimiter is tab
  21. 2       5
  22. 3       6
  23.  
  24. $ paste -s a b
  25. 1       2       3
  26. 6       5       4
  27.  
  28. $ cat c
  29. a
  30. b
  31. c
  32. d
  33.  
  34. $ paste -d "," a c
  35. 1,a
  36. 2,b
  37. 3,c
  38. ,d
  39.  
  40.         #paste can also be applied to single file
  41.         #useful to convert columns to rows
  42. $ paste -s c   
  43. a       b       c       d
  44. $ paste -d, -s  c    
  45. a,b,c,d
  46.  
  47. $ ls *.txt | paste -s -d " "  -         #check this out
  48. $ ls *.txt | xargs                      #comparable to this
  49.  
  50.  
  51. $ paste - - < c         #joins two lines at a time
  52. a       b               # since - is standard ouput
  53. c       d               #can also join three (- - -) at a time also
  54.  
  55. $ cat file1 | paste -d, file1 -   #input file can be a pipe
  56.  
  57. $ paste -d '\n' a b     #will intersperse merge file1 and file2
  58. 1
  59. 6
  60. 2
  61. 5
  62. 3
  63. 4
  64.  
  65. $ paste -s -d ";," a b  #feature! Try longer columns and more delimiters
  66. 1,2;3
  67. 4,5;6
  68.  
  69.  
  70.  
  71. RESOURCES:
  72. http://www.theunixschool.com/2012/07/10-examples-of-paste-command-usage-in.html

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.