1833875 Members
3234 Online
110063 Solutions
New Discussion

Script help

 
Francois Bariselle_3
Regular Advisor

Script help

Hi all,

In a file, I want add a string "CC" 2 lines before a know string "C".

Ex.:

My original file is :

A
B
??? --> unknown string
C
D

The result would be :

A
B
CC
???
C
D

How I do this with awk.

Thanks in advance.

Frank



Fais la ...
4 REPLIES 4
Pete Randall
Outstanding Contributor

Re: Script help

James R. Ferguson
Acclaimed Contributor

Re: Script help

Hi Frank:

Well, this case is the cousin of your other thread. This will work:

#!/usr/bin/sh
sed '/^B/{
n
iCC
}' filename
exit 0

Regards!

...JRF...
Pete Randall
Outstanding Contributor

Re: Script help

Sorry, Frank - at first glance I thought they were the same.

Pete

Pete
H.Merijn Brand (procura
Honored Contributor

Re: Script help

And what should

A
B
C
C
A
C

turn in to?

A
CC
B
CC
C
C
CC
A
C

?

if there is no such conflicts possible,

l1:/tmp 106 > cat xx
A
B
??? --> unknown string
C
D
l1:/tmp 107 > perl -ne'@p>1&&print shift@p;/C/&&print"CC\n";push@p,$_}END{print@p' xx
A
B
CC
??? --> unknown string
C
D
l1:/tmp 108 >

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn