|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Append using SED/AWK
Hi friends,
I have a file with content SOME TEXT HERE I want to append the string GREAT to Line 1 of my file such that the file content should be GREAT SOME TEXT HERE I can do a cat for the string great and file >> newfile and then rename newfile name to file But this does not put GREAT at Line1. It writes in one single line like GREAT SOME TEXT HERE. Is there any better way to do this? May be using SED/AWK? Also please show some pointers to SED/AWk tutorials I would like to start learning them. |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Try: Code:
awk 'NR==1{print "GREAT"; }NR ' file |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Great! Thank you it works and can you please guide me to some good SED/AWK tutorials?
|
|
#4
|
|||
|
|||
|
Awk...
Awk - A Tutorial and Introduction - by Bruce Barnett Sed... Sed - An Introduction and Tutorial regards, |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
or Code:
sed '1i GREAT' file cheers, Devaraj Takhellambam |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Using sed: append one line in header of the file. See the following example: Code:
cat file
SOME TEXT HERE
sed -i '1{s/^/GREAT\n/}' file
cat file
GREAT
SOME TEXT HERE |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to append using sed | asirohi | Shell Programming and Scripting | 2 | 08-24-2009 10:39 AM |
| append a ' to the $1 $2 | ppass | Shell Programming and Scripting | 2 | 05-26-2008 09:59 AM |
| Append using awk | Raynon | Shell Programming and Scripting | 4 | 11-04-2007 05:19 AM |
| ftp append | brdholman | UNIX for Dummies Questions & Answers | 1 | 10-31-2007 09:02 AM |
| append to fle using sed | shweta_d | Shell Programming and Scripting | 2 | 06-13-2007 02:57 AM |
|
|