Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I do this with SED? If not what can I do it with? 1

Status
Not open for further replies.

DanNJ

MIS
Mar 19, 2003
29
0
0
US
Input File
line 1
line 2
line 3
line 1
line 2
line 3
line 1
line 2
line 3
line 4

Output File
line 1
line 2
line 3
line 1
line 2
line 3
line 1
Line Added
line 2
line 3
line 4
 
you can do it with MANY tools as there's always more than 1 way to skin that cat.

What determines what line number [or any other condition] you want to add 'Line Added'?
1. every 8-th line?
2. every 3rd block of 3-line blocks after the 1st line?
3. ???

What is it?
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Whenever line 4 occurs add a line between the previous Line 1 and Line 2.

Their will be up to 48 Line 4’s with a varying number of line 12&3’s between them.
 
I like a good puzzle...
[tt]
awk 'BEGIN {b=&quot;&quot;}
{ if (b > &quot;&quot;) b=b &quot;\n&quot; $0; else b=$0}
/line 1/ {print b;b=&quot;&quot;}
/line 4/ {print &quot;line added\n&quot; b;b=&quot;&quot;}
END {print b}' < file1
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top