rednaxela
rednaxela

Reputation: 801

Script to edit a text file on a Linux Redhat Server

The task I am trying to achieve is to write a script which accesses a Red Hat Server, navigates to a certain directory, and adds things to a text file. How would I go about this task? what scripting language do I use? etc.

I don't have any experience in scripting languages, I'm only really an expert in Java applications and occasional C#.

Hope somebody can help. This would be extremely useful to me.

Upvotes: 0

Views: 760

Answers (1)

Greyson
Greyson

Reputation: 3688

If you're just trying to append a line, you can use SSH (for the connection) and just concatenate to the end of the file like so:

echo "New line to text file" | ssh myserver.com 'cat >> /var/myfile.txt'

If you're trying to change the contents, then you'll need to download the file before running it through a utility such as sed or awk and then uploading it back to the server. scp can be used to securely download and upload the file, but describing sed or awk here is beyond the scope of a brief answer.

Upvotes: 2

Related Questions