There is a sed
way:
f1width=$(wc -L <one.txt)
f1blank="$(printf "%${f1width}s" "")"
paste one.txt two.txt |
sed "
s/^\(.*\)\t/\1$f1blank\t/;
s/^\(.\{$f1width\}\) *\t/\1 /;
"
Under bash, you could use printf -v
:
f1width=$(wc -L <one.txt)
printf -v f1blank "%${f1width}s"
paste one.txt two.txt |
sed "s/^\(.*\)\t/\1$f1blank\t/;
s/^\(.\{$f1width\}\) *\t/\1 /;"
(Of course @Hasturkun 's solution pr
is the most accurate!):
Advantage of sed
over pr
You can finely choose separation width and or separators:
f1width=$(wc -L <one.txt)
(( f1width += 4 )) # Adding 4 spaces
printf -v f1blank "%${f1width}s"
paste one.txt two.txt |
sed "s/^\(.*\)\t/\1$f1blank\t/;
s/^\(.\{$f1width\}\) *\t/\1 /;"
Or, for sample, to mark lines containing line
:
f1width=$(wc -L <one.txt)
printf -v f1blank "%${f1width}s"
paste one.txt two.txt |
sed "s/^\(.*\)\t/\1$f1blank\t/;
/line/{s/^\(.\{$f1width\}\) *\t/\1 |ln| /;ba};
s/^\(.\{$f1width\}\) *\t/\1 | | /;:a"
will render:
apple | | The quick brown fox..
pear | | foo
longer line than the last two |ln| bar
last line |ln| linux
| |
|ln| skipped a line