Computing.Net > Forums > Unix > Help with grep/awk

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.

Help with grep/awk

Reply to Message Icon

Name: VJ
Date: September 16, 2003 at 12:19:54 Pacific
OS: AIX
CPU/Ram: 4 CPU
Comment:

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 store

dt,doe_j,PWQ,/ABCDEFGH in a file.
I used grep and awk but could not write the line above user. Any help is appreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: VJSingh
Date: September 16, 2003 at 23:06:23 Pacific
Reply:

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 Doe

This 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! !


0

Response Number 2
Name: WilliamRobertson
Date: September 17, 2003 at 05:44:53 Pacific
Reply:

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".



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Order by Date MM/DD/YY He... editor in unix



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: Help with grep/awk

need help with grep.... www.computing.net/answers/unix/need-help-with-grep/7366.html

Help with grep www.computing.net/answers/unix/help-with-grep/4821.html

Help with AWK to extract text block www.computing.net/answers/unix/help-with-awk-to-extract-text-block/7987.html