Sponsored Content
Top Forums Shell Programming and Scripting [AWK] handeling data spread on multiple lines Post 302503613 by maverick72 on Friday 11th of March 2011 05:30:09 AM
Old 03-11-2011
[AWK] handeling data spread on multiple lines

Hello all,

first off great forum.

Now for my little problem.

Using RHEL 5.4 and awk. Been doing code since a few month. So just starting.

My problem is handeling data on multiple lines.

Code:
{
if ($1 != LASTKEY && h["canonicalName"] ~ /.*\/s_fr_[a-z]/)  {
        checkgecos( h["unixname"], h["gecos"] ) 
        h[unixname]=""
        h[gecos]=""
}
if ($2 == "gecos" || $2 == "unixname" || $2 == "canonicalName") {
        h[$2] = $3
}
LASTKEY = $1
}

This code handles great the following data:

toto1:unixname:toto1
toto1:uid:4567
toto1:gecos:Toto Toto
toto1:canonicalName:us.bla.bla.bla
bob2:unixname:bob2
bob2:uid:7676
....

But i can't figure out how to handle this kind of data spread on multiple lines (ex: sudo.log file)

Mar 9 17:24:28 : toto : TTY=pts/2 ; PWD=/home/toto ; USER=root
; COMMAND=/bin/cat /var/log/sudo.log

Of course to add more problem... It can be spread on more then 2 lines...

Jan 29 12:10:50 : toto : TTY=unknown ; PWD=/home/toto ; USER=root ;
COMMAND=/bin/nice find / /export /boot blablabla -mount
-type f -name catalina.jar -o -name license.bea -o -name weblogic.jar -o
-name httpd -o -name config.nice

Tried with a while and getline to get second line but that didn't seem to do the trick.

What are you guy's tricks for handleling multiple line data?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Handeling multiple options in script

i need to be able to handel if multiple commands are passed into my script. (ie) -f -r -i . does anyone know a simple solution to handeling this. Thanks (2 Replies)
Discussion started by: virus_stinger
2 Replies

2. UNIX for Dummies Questions & Answers

Can I spread commands over multiple lines?

Below an example of what I mean. The first attempt does what I want; the second doesn't, because bash assumes a line break means the end of an individual "command unix". Is there some way that I can convince bash to parse out, eg, to the closing parenthesis? I'm thinking this would allow for... (1 Reply)
Discussion started by: tphyahoo
1 Replies

3. Programming

spawning multiple processes spread across two files

I want to spawn n child processes but have two different classes..with the foremost one forking/spawning the child process and the latter performing a function w/ the spawned processes. I can do this in one class with an if statement and the simple if((pid=fork())==0) //child process { ... (1 Reply)
Discussion started by: StrengthThaDon
1 Replies

4. Shell Programming and Scripting

removing pattern which is spread in multiple lines

I have several huge files wich contains oracle table creation scripts as follows: I would need to remove the pattern colored in red above. Any sed/awk/pearl code will be of much help. Thanks (2 Replies)
Discussion started by: sabyasm
2 Replies

5. Shell Programming and Scripting

search for a string spread in multiple line

Hi, I have to look for the full string below in a large file(>5GB) , but that string may be spread in two lines. string :-- "f8f8 f5f0 f0f0 f1f7 f4f7 f7c1" By grep "f8f8 f5f0 f0f0 f1f7 f4f7 f7c1" file | tail -1 , I am getting incorrect result because there is a line after this also which... (1 Reply)
Discussion started by: finder255
1 Replies

6. UNIX for Dummies Questions & Answers

how to fill the name of the spread sheet as a cell's data

In open office spreadsheet, i would like to fill a cell with the name of the spread sheet. That is if the file name of spread sheet is, team.ods, then i have to fill a specific cell with that name 'team'. How to do that ? I have more spread sheets to be created, so i want it to be done... (0 Replies)
Discussion started by: thegeek
0 Replies

7. Shell Programming and Scripting

FTP GET with exception handeling and multiple conditions

Thanks everyone for the wonderful and helping environment.. And the problem I asked.. forget it... 4 days wait for a decent reply was such a moral booster.. (3 Replies)
Discussion started by: ReignOfChaos
3 Replies

8. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

9. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies

10. UNIX for Beginners Questions & Answers

Remove newline character from column spread over multiple lines in a file

Hi, I came across one issue recently where output from one of the columns of the table from where i am creating input file has newline characters hence, record in the file is spread over multiple lines. Fields in the file are separated by pipe (|) delimiter. As header will never have newline... (4 Replies)
Discussion started by: Prathmesh
4 Replies
TZSELECT(8)						      System Manager's Manual						       TZSELECT(8)

NAME
tzselect - select a time zone SYNOPSIS
tzselect DESCRIPTION
The tzselect program asks the user for information about the current location, and outputs the resulting time zone description to standard output. The output is suitable as a value for the TZ environment variable. All interaction with the user is done via standard input and standard error. ENVIRONMENT VARIABLES
AWK Name of a Posix-compliant awk program (default: awk). TZDIR Name of the directory containing time zone data files (default: /usr/local/etc/zoneinfo). FILES
TZDIR/iso3166.tab Table of ISO 3166 2-letter country codes and country names. TZDIR/zone.tab Table of country codes, latitude and longitude, TZ values, and descriptive comments. TZDIR/TZ Time zone data file for time zone TZ. EXIT STATUS
The exit status is zero if a time zone was successfully obtained from the user, nonzero otherwise. SEE ALSO
newctime(3), tzfile(5), zdump(8), zic(8) TZSELECT(8)
All times are GMT -4. The time now is 03:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy