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!

Alternate Printing of Lines Within a File

Status
Not open for further replies.

Mariko

ISP
Oct 2, 2001
17
0
0
US
Hi There,
Another question on printing out lines in a file.
Example:
Given Input File Desired Output File
1 1
2 1.1
3 2
1.1 1.2
1.2 3
Any help on generating the output file would be truly appreciated.
Thanks again!
-Mariko

 
Hi Mariko,

If I understand your problem correctly, this should do it.

BEGIN
{
while ((getline < &quot;file1&quot;) > 0) {
i++;
if (i%2) print
}
close(&quot;file1&quot;)
i = 0
while ((getline < &quot;file1&quot;) > 0) {
i++;
if (!(i%2)) print
}
exit
}

Hope this helps.

CaKiwi
 
Why don't you try [tt]sort -n < inputfile > outputfile[/tt]?
I hope it works...
Unix was made by and for smart people.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top