How two unsorted text files of different lengths will be displayed side by side (in columns) in the shell
Given one.txt and two.txt :
$ cat one.txt apple pear longer line than the last two last line $ cat two.txt The quick brown fox.. foo bar linux skipped a line
Display:
apple The quick brown fox.. pear foo longer line than the last two bar last line linux skipped a line
paste one.txt two.txt almost does the trick, but doesn't align the columns nicely, as it just prints one tab between columns 1 and 2. I know how to do this with emacs and vim, but I want the output to be output to stdout for pipeline ect.
The solution I came up with uses sdiff and then goes to sed to remove the sdiff output.
sdiff one.txt two.txt | sed -r 's/[<>|]//;s/(\t){3}//'
I could create a function and paste it into my .bashrc , but of course there is already a command for this (or a potential solution for cleaning)?
command-line linux unix shell gnu-coreutils
Chris Seymour Nov 12 '12 at 10:15 2012-11-12 10:15
source share