I have two files which both contain a list of words. Is there an easy way to zip the contents of the files into one new file in bash, so that the resultant file would have two columns like this:
file1_line1 file2_line1 file1_line2 file2_line2 file1_line3 file2_line3 file1_line4 file2_line4
paste
-- merge corresponding or subsequent lines of files
paste [-s] [-d list] file ...
The paste
utility concatenates the corresponding lines of the given input files, replacing all but the last file's newline characters with a single tab character, and writes the resulting lines to standard output.
Paste will get you half way there, but you'll need sed to append the file name to the words
Put this into a shell script and pass it the two files as arguments
#!/bin/sh paste $1 $2 | sed -e "s/^\([^ ]\+\)\s\+\([^ ]\)/$1_\1 $2_\2/"
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