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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append new line.

Status
Not open for further replies.

shaokat

Technical User
Oct 8, 2002
11
IN
I have the foll input file:

=============
1 TRUMAN
- CLINTON
0 GEORGE
===========EOF
For every 1st char, I have to do the following:
if 1st char is - leave 1 line before.
if 1st char is 0 leave 2 line before.

This is the expected output.
=============
1 TRUMAN

CLINTON


GEORGE
===========EOF

TIA,
KAT

 
Code:
awk ' {

                if ($1 == "-") {
                   printf "\n%s", $2 ; next
                }

                if ($1 == "0") {
                   printf "\n\n\n%s\n", $2 ; next
                }

                print $0
}' scrap.txt
 
my version:

awk '
/^0 /{$1="\n\n";}
/^- /{$1="\n";}
{print;} # see NOTA
' scrap.txt

#NOTA: the print statement is my be not needed, awk prints by default, but i am not on my unix box actually.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top