Computing.Net > Forums > Unix > Reading previous line

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Reading previous line

Reply to Message Icon

Name: Sayeed
Date: August 6, 2003 at 16:00:10 Pacific
OS: UnixWare
Comment:

Hello,

Currently am positioning at the 100th line with the AWK. How can I read & print its previous line#99th.
Your reply is greatly appreciated.
Thanks!!



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: August 7, 2003 at 12:18:47 Pacific
Reply:

In the code below, for each line the if-statement selects (as coded it will be only the 100th line) it will print the previous line and the triggering line:

awk '{
if (FNR==100)
   {print "Prevline: " holdline
    print "Currline: " $0}
holdline=$0
}' myfile


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Reading previous line

read multiple lines www.computing.net/answers/unix/read-multiple-lines/7940.html

Print previous line www.computing.net/answers/unix/print-previous-line/8260.html

reading 2 lines and comparing them www.computing.net/answers/unix/reading-2-lines-and-comparing-them/6861.html