I tried almost everything, sed, awk, tr
, but...
I'm trying to output a file containing this
2079 May 19 13:37 temp.sh
1024 May 23 17:09 mirrad
478 May 26 14:48 unzip.sh
like this
2079
May
19
13:37
.
.
.
So each string will be printed out one at the time in a variable.
Another simple one liner using xargs
xargs -n 1 <file
where -n
explanation from man
page:-
-n max-args, --max-args=max-args
Use at most max-args arguments per command line. Fewer than
max-args arguments will be used if the size (see the -s
option) is exceeded, unless the -x option is given, in which
case xargs will exit.
will produce output as
#!/bin/bash
$ xargs -n1 <tmp.txt
2079
May
19
13:37
temp.sh
1024
May
23
17:09
mirrad
with -n
value as 2 it gives
#!/bin/bash
$ xargs -n2 <tmp.txt
2079 May
19 13:37
temp.sh 1024
May 23
17:09 mirrad
Note
The suggestion with xargs
only works for a simple input as shown in OP. As such the solution doesn't work for huge files (needing high in memory processing) or in files containing lines with quotes. See other answers involving awk
for the same.
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