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

awk (previous value)

Status
Not open for further replies.

AliAmanAmarAdel

Programmer
Joined
Jul 10, 2000
Messages
6
Location
US
I have been trying to print previous value of a column when the value of the current column is blank?<br>ie..<br>yesterday&nbsp;&nbsp;&nbsp;&nbsp;07/09/00<br>today&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;07/10/00<br>thisday&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>tommorow&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;07/11/00 <br><br>when the second column is &quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot; I want to print &quot;07/10/00&quot;.<br>I have not been able to store value of a previous line in AWK?<br><br>Any suggestions?
 
This should work for you.<br><br>Put your example input into a file called &quot;infile&quot;, then, run this awk one line script from the command line.<br><br>cat infile ¦ awk '{ if( $2 ) prev = $2 } { if( NF == 1 ) $1 = $1&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;prev } { print }'<br><br><br>Hope this helps you.<br><br> <p>flogrr<br><a href=mailto:flogr@yahoo.com>flogr@yahoo.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top