I have this list
111
222
333
444
555
I want to print each line to have 2 coupled args, like this:
111 222
222 333
333 444
444 555
555
Is there a way to do this with xargs? or any single liner command (performance is important)
thanks
CodePudding user response:
You could also use paste
with two inputs: One as the original file and one with the first line stripped off (here by using tail -n 2
):
Using process substitution:
paste file.txt <(tail -n 2 file.txt)
Using a pipeline (as suggested by @pjh):
tail -n 2 file.txt | paste file.txt -
Both output
111 222
222 333
333 444
444 555
555
CodePudding user response:
awk
seems more appropriate than xargs
:
$ awk 'NR>1 {print prev, $0} {prev=$0} END {print prev}' file.txt
111 222
222 333
333 444
444 555
555
CodePudding user response:
With xargs
and an inline shell script:
xargs -a list.txt sh -c 'while [ $# -gt 0 ]; do printf %s\ %s\\n "$1" "$2"; shift; done' _