Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AAAA
- BBBB
- CCCC
- DDDD
- 1234
- 5678
- 9012
- 3456
- EEEE
- 7890
- AAAA 1234
- BBBB 5678
- CCCC 9012
- DDDD 3456
- EEEE 7890
- use warnings;
- use strict;
- ## Check arguments.
- die qq[Usage: perl $0 <input-file>n] unless @ARGV == 1;
- my (@alpha, @digit);
- while ( <> ) {
- ## Omit blank lines.
- next if m/As*Z/;
- ## Remove leading and trailing spaces.
- s/As*//;
- s/s*Z//;
- ## Save alphanumeric fields and fields with
- ## only digits to different arrays.
- if ( m/A[[:alpha:]]+Z/ ) {
- push @alpha, $_;
- }
- elsif ( m/A[[:digit:]]+Z/ ) {
- push @digit, $_;
- }
- }
- ## Get same positions from both arrays and print them
- ## in the same line.
- for my $i ( 0 .. $#alpha ) {
- printf qq[%s %sn], $alpha[ $i ], $digit[ $i ];
- }
- AAAA
- BBBB
- CCCC
- DDDD
- 1234
- 5678
- 9012
- 3456
- EEEE
- 7890
- perl script.pl infile
- AAAA 1234
- BBBB 5678
- CCCC 9012
- DDDD 3456
- EEEE 7890
- awk -v RS="" '{for(i=1; i<=NF; i++) a[i]=$i
- getline
- for(i=1; i<=NF; i++) print a[i] " " $i
- print ""}' file
- <input sed -nr '/^[A-Z]{4}$/,/^$/w out1
- /^[0-9]{4}$/,/^$/w out2'
- paste -d' ' out1 out2 |sed 's/^ $//'
- paste -d' ' <(sed -nr '/^[A-Z]{4}$/,/^$/p' input)
- <(sed -nr '/^[0-9]{4}$/,/^$/p' input) | sed 's/^ $//'
- perl -M5.010 -lne '
- given ($_) {
- when (/^[[:alpha:]]+$/) {push @alpha, $_}
- when (/^d+$/) {say shift(@alpha), " ", $_}
- default {say}
- }
- '
- $ pr -mt <(grep -i "^[a-z]" file.txt) <(grep -i "^[0-9]" file.txt)
- AAAA 1234
- BBBB 5678
- CCCC 9012
- DDDD 3456
- EEEE 7890
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement