I want to cut fields separately from two different files, file1.txt and file2.txt, and store the output in a new file, output.txt. I know how to do it for one file. Can someone help me out at this?
cut -d"," -f 1,3 file1.txt > output.txt
I want to do something like:
cut ( -d"," -f 1,3 file1.txt ) && ( -d"," -f 1,2 file2.txt ) > output.txt
Maybe you're looking for this:
paste -d, <(cut -d, -f1,3 file1.txt) <(cut -d, -f1,2 file2.txt) > output.txt
That assumes that you want fields 1 and 3 of the first file and 1 and 2 of the second file to all appear on a single line of the output.
<(...) is process substitution (not a redirect), which creates a name for a pipe containing the output of the enclosed command. paste just pastes together lines from its arguments, using whatever character is provided with the -d argument as a delimiter. See man paste.
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