1830226 Members
1566 Online
109999 Solutions
New Discussion

Script help

 
SOLVED
Go to solution
Francois Bariselle_3
Regular Advisor

Script help

Hi all,

In a file, I want add a string "CC" 2 lines after a know string "B".

Ex.:

My original file is :

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

The result would be :

A
B
???
CC
C
D

How I do this.

Thanks in advance.

Frank



Fais la ...
8 REPLIES 8
Jdamian
Respected Contributor

Re: Script help

You can use 'awk'

awk '/B/ { print; getline; print; print "CC"; continu } {print}'
Jdamian
Respected Contributor

Re: Script help

You can use 'awk'

awk '/B/ { print; getline; print; print "CC"; continue } {print}'
Jdamian
Respected Contributor

Re: Script help

You can use 'awk'

awk '/^B/ { print; getline; print; print "CC"; continue } {print}'
John Meissner
Esteemed Contributor

Re: Script help

do you think you can use awk? tripple post above :)
All paths lead to destiny
Francois Bariselle_3
Regular Advisor

Re: Script help

Hi again,

There are many occurence of "B" in my file and I don't know the lines numbers. I want add "CC" 2 line after all occurence of "B"

regards,

Frank.
Fais la ...
Jean-Louis Phelix
Honored Contributor
Solution

Re: Script help

Hi,

The script which was given will work for evry occurence. Just try it.

Regards.
It works for me (© Bill McNAMARA ...)
Jean-Louis Phelix
Honored Contributor

Re: Script help

Hi,

The script which was given will work for every occurence. Just try it.

Regards.
It works for me (© Bill McNAMARA ...)
James R. Ferguson
Acclaimed Contributor

Re: Script help

Hi:

Here's a 'sed' solution:

#!/usr/bin/sh
sed '/^B/{
n
aCC
}' inputfile
exit 0

Regards!

...JRF...