Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a log file that has the following pattern.
col1 col2 col3
-- -- PWQ,/ABCDEFGH,E:/dir1/dir2/file
Dt USR doe_j
I need to storedt,doe_j,PWQ,/ABCDEFGH in a file.
I used grep and awk but could not write the line above user. Any help is appreciated.

Any suggestions? OK I will elaborate a little better.
There are 3 columns in the log file, and I need the name of the object in line(above the time the object was accessed and the user who accessed it). I need to put the object name,time and username in a flat file.
Column1 Column2 Column3
-- -- PWQ,/Object Name,C:dir
09/16/2003 USR John DoeThis is the nature of the file, Now I need to put line1column3,line2column1,line2column3 in one flat file. i.e.
PWQ,/Object Name,09/16/2003,John Doe.
Using grep and awk I am able to get line2column1,line2column3, but am stuck at getting data from the line above it.
Any suggestions,comments please! !

In awk you could explicitly copy each line to a variable and then do something with that when you read the next line - very basic example:
awk '{if ($1 == "--") storedrec = $0; else print $0, storedrec}' test.file
I'm pretty sure sed could do this though. Have a look at Eric Pement's "Handy one-liners for sed".

![]() |
Order by Date MM/DD/YY He...
|
editor in unix
|

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