linux - extracting two ranges of lines of a file a and putting them as a data block with shell commands -
i have 2 blocks of data in file, foo.txt
following:
a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 9
i'd extract rows 2:4
, 6:8
, put them following:
b 2 f 6 c 3 g 7 d 4 h 8
i try using auxiliary files:
sed -n '2,4p' foo.txt > tmp1; sed -n '6,8p' foo.txt > tmp2; paste tmp1 tmp2 > output; rm tmp1 tmp2
but there better way without auxiliary files? thanks!
using process substitution:
$ paste <(sed -n '2,4p' foo.txt) <(sed -n '6,8p' foo.txt) > output $ cat output b 2 f 6 c 3 g 7 d 4 h 8 $
Comments
Post a Comment