add line on a file with sed or awk

  • Follow


Hi all,

I need to add one only string (ADD) after a search pattern (SEARCH),
I tryied these:

awk '{print}/SEARCH/{print "ADD"}' file

sed -e '/SEARCH/aADD' file

but all of them make the "adding" for all the search pattern, I have to
add only the first time the search pattern occurred..

really thanx all

0
Reply Davide 8/8/2006 8:22:39 PM

Davide wrote:
> Hi all,
> 
> I need to add one only string (ADD) after a search pattern (SEARCH),
> I tryied these:
> 
> awk '{print}/SEARCH/{print "ADD"}' file
> 
> sed -e '/SEARCH/aADD' file
> 
> but all of them make the "adding" for all the search pattern, I have to
> add only the first time the search pattern occurred..
> 
> really thanx all
> 


awk '{print}/SEARCH/{if(didit!=1) { print "ADD"; didit=1;}}' file
0
Reply Harm 8/8/2006 9:05:39 PM


oh my god!
:)

Harm Van Houten ha scritto:

> Davide wrote:
> > Hi all,
> >
> > I need to add one only string (ADD) after a search pattern (SEARCH),
> > I tryied these:
> >
> > awk '{print}/SEARCH/{print "ADD"}' file
> >
> > sed -e '/SEARCH/aADD' file
> >
> > but all of them make the "adding" for all the search pattern, I have to
> > add only the first time the search pattern occurred..
> >
> > really thanx all
> >
>
> 
> awk '{print}/SEARCH/{if(didit!=1) { print "ADD"; didit=1;}}' file

0
Reply Davide 8/8/2006 9:23:41 PM

2 Replies
839 Views

(page loaded in 0.054 seconds)

Similiar Articles:













7/23/2012 2:59:13 PM


Reply: