I have two files containing as below
cat file1.txt
a b c
1 2 3
cat file2.txt
a
b
c
1
2
3
I want file1 to be arranged as
a
b
c
1
2
3
and file2 to be arranged as
a b c
1 2 3
I would like a solution using awk one line
For example: awk -F, ' program ' input-files. sets FS to the ' , ' character. Notice that the option uses an uppercase ' F ' instead of a lowercase ' f '. The latter option ( -f ) specifies a file containing an awk program.
The awk implementation of cut uses the getopt() library function (see Processing Command-Line Options) and the join() library function (see Merging an Array into a String). The current POSIX version of cut has options to cut fields based on both bytes and characters.
awk Built-in Variables ORS - Output Record Separator This variable is used to set output record separator, by default a newline.
AWK NF in Ubuntu 20.04: The “NF” AWK variable is used to print the number of fields in all the lines of any provided file. This built-in variable iterates through all the lines of the file one by one and prints the number of fields separately for each line.
I'd use xargs
for this:
$ xargs -n1 < file1
a
b
c
1
2
3
$ xargs -n3 < file2
a b c
1 2 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With