Showing posts with label Add one file's contents in other file on Remote host using command line. Show all posts
Showing posts with label Add one file's contents in other file on Remote host using command line. Show all posts

Wednesday, June 26, 2013

Add one file's contents in other file on Remote host using command line

Add one file's text in another file on remote host :

If you have a file A and you want to add this whole file's text in file B but the problem is file B is on remote host.

You may be think to download the file B, update it and upload it again.

But you can do this using command line in a single command.

Suppose file A which is on your system is in  /root directory and file B which is on Remote host is in /root/Documents.

Now run following commands to add file A's text in file B.
# cat /root/fileA.txt | ssh 192.168.xx.xx "cat >> /root/Documents/fileB.txt"
or
# ssh 192.168.xx.xx "cat >> /root/Documents/fileB.txt" </root/fileA.txt
or
# scp /root/fileA.txt 192.168.xx.xx: /root/fileA.txt && ssh 192.168.xx.xx "cat /root/fileA.txt >>  /root/Documents/fileB.txt"
where:
192.168.xx.xx is IP of Remote Host

The commands do not remove the text of fileB instead they add the text at bottom of the fileB.