I need a very simple (hopefully) 1 liner command that reads in a file appends a string and outputs to a new file, without changing the original data.
file1 string
------ ------
apple oranges
bananas
MAGIC COMMAND
filel file2
------ ------
apple apple
bananas bananas
oranges
basically, cat file1 + 'oranges' > file2
I'm using autosys to run the command, and I'm pretty sure it doesn't allow for &&
or ;
as part of a single command.
Type the cat command followed by the file or files you want to add to the end of an existing file. Then, type two output redirection symbols ( >> ) followed by the name of the existing file you want to add to.
You do this by using the append redirection symbol, ``>>''. To append one file to the end of another, type cat, the file you want to append, then >>, then the file you want to append to, and press <Enter>.
The join command in UNIX is a command line utility for joining lines of two files on a common field.
To concatenate files, we'll use the cat (short for concatenate) command.
You can do this:
(cat file1 ; echo 'oranges') > file2
Which will spawn one subshell, which will cat file1 to stdout, then echo oranges to stdout. And we capture all that output and redirect it to a new file, file2.
Or these 2 commands:
cp file1 file2
echo 'oranges' >> file2
Which first copies file1 to the new file2, and then appends the word oranges to file2
Here's another one liner that does not use ; nor &&
echo oranges | cat file1 - > file2
awk '1; END{ print "oranges"}' file1 > file2
You can probably use the standard solution (given by nos) if you pass it as a string to sh:
sh -c 'cat file1; echo oranges' > file2
Then this should do it:
$cat file1 >> file2; echo "orange" >> file2;
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