Re: [Hampshire] Quick question

Top Page

Reply to this message
Author: Simon Reap
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Quick question
Paul Tansom wrote:
> ** Keir Whitlock <keir.whitlock@???> [2007-12-20 09:01]:
>
>> Hi,  
>>    A quick one for you,  echo "hi" >> /tmp/file will append hi to the 
>> end of file, but how do I prepend it to the top of the file?

>>
> ** end quote [Keir Whitlock]
>
> How's about:
>
> sed -i.bak '1 s/^/Hi\n/' file.txt
>
> I'm far from being an expert, but sed and awk are mighty powerful tools
> if you can get to grips with them, this is just scratching the surface
> of one of them!
>

awk version:

    mv file.txt file.txt.bak ; awk 'BEGIN{print "Hi"}{print}' 
file.txt.bak > file.txt


Simon