Advertisement
Guest User

Untitled

a guest
May 5th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. AAAA
  2. BBBB
  3. CCCC
  4. DDDD
  5.  
  6. 1234
  7. 5678
  8. 9012
  9. 3456
  10.  
  11. EEEE
  12.  
  13. 7890
  14.  
  15. AAAA 1234
  16. BBBB 5678
  17. CCCC 9012
  18. DDDD 3456
  19.  
  20. EEEE 7890
  21.  
  22. use warnings;
  23. use strict;
  24.  
  25. ## Check arguments.
  26. die qq[Usage: perl $0 <input-file>n] unless @ARGV == 1;
  27.  
  28. my (@alpha, @digit);
  29.  
  30. while ( <> ) {
  31. ## Omit blank lines.
  32. next if m/As*Z/;
  33.  
  34. ## Remove leading and trailing spaces.
  35. s/As*//;
  36. s/s*Z//;
  37.  
  38. ## Save alphanumeric fields and fields with
  39. ## only digits to different arrays.
  40. if ( m/A[[:alpha:]]+Z/ ) {
  41. push @alpha, $_;
  42. }
  43. elsif ( m/A[[:digit:]]+Z/ ) {
  44. push @digit, $_;
  45. }
  46. }
  47.  
  48. ## Get same positions from both arrays and print them
  49. ## in the same line.
  50. for my $i ( 0 .. $#alpha ) {
  51. printf qq[%s %sn], $alpha[ $i ], $digit[ $i ];
  52. }
  53.  
  54. AAAA
  55. BBBB
  56. CCCC
  57. DDDD
  58.  
  59. 1234
  60. 5678
  61. 9012
  62. 3456
  63.  
  64. EEEE
  65.  
  66. 7890
  67.  
  68. perl script.pl infile
  69.  
  70. AAAA 1234
  71. BBBB 5678
  72. CCCC 9012
  73. DDDD 3456
  74. EEEE 7890
  75.  
  76. awk -v RS="" '{for(i=1; i<=NF; i++) a[i]=$i
  77. getline
  78. for(i=1; i<=NF; i++) print a[i] " " $i
  79. print ""}' file
  80.  
  81. <input sed -nr '/^[A-Z]{4}$/,/^$/w out1
  82. /^[0-9]{4}$/,/^$/w out2'
  83. paste -d' ' out1 out2 |sed 's/^ $//'
  84.  
  85. paste -d' ' <(sed -nr '/^[A-Z]{4}$/,/^$/p' input)
  86. <(sed -nr '/^[0-9]{4}$/,/^$/p' input) | sed 's/^ $//'
  87.  
  88. perl -M5.010 -lne '
  89. given ($_) {
  90. when (/^[[:alpha:]]+$/) {push @alpha, $_}
  91. when (/^d+$/) {say shift(@alpha), " ", $_}
  92. default {say}
  93. }
  94. '
  95.  
  96. $ pr -mt <(grep -i "^[a-z]" file.txt) <(grep -i "^[0-9]" file.txt)
  97. AAAA 1234
  98. BBBB 5678
  99. CCCC 9012
  100. DDDD 3456
  101. EEEE 7890
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement