Sunday, December 30, 2007

fun with bash: append text to a file

There is time when we need to edit a file on linux, or unix for that matter, and usually a configuration file. And to me at least, it is usually append to end of a file.

On the other hand, unix got many many, text manipulating utilities, and often, one liner to do text manipulation exist. From cat, to sed. And some an echo will do.

To append a line to a file, it just
echo "your text">> yourFile
here's a bit explaination, in layman term
echo "your text"
will by default, print to your screen, which comes to
>>
which means, redirect output to, somewhere. Another variation is, >, the difference is that, this will replace, the whole thing. >> will append
>> yourFile
means redirect to your file.

And there you go, a one line to append a file.

No comments:

Post a Comment