awk related question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk related question
# 1  
Old 11-07-2012
awk related question

Code:
awk -F ";" 'FNR==NR{a[$0]=$1;next} ($2 in a)' server.list datafile | while read line 
do
        echo ${line}
done

when i run the above, i get this:

Code:
1 SERVICE NOTIFICATION: nagiosadmin skysmart-01.sky.net ....

instead of:
Code:
[1352267653] SERVICE NOTIFICATION: nagiosadmin skysmart-01.sky.net ....

can someone help me modify the awk statement?

linux/sunos
bash

---------- Post updated at 02:30 PM ---------- Previous update was at 01:14 PM ----------

what i really wanna do is translate the epoch times on the lines.

i need something like this:

Code:
cat file | perl -pe "s/(\d+)/localtime($1)/e" | while read line
do
echo $line 
done

i want the resulting lines to have the translated date and time and also the epoch time as well.

something like this:

Code:
Wed Nov  7 19:28:46 UTC 2012 [1352267653] SERVICE NOTIFICATION: nagiosadmin skysmart-01.sky.net ....

notice how the translated time is shown, and is followed by epoch time?? any ideas?

Last edited by SkySmart; 11-07-2012 at 02:31 PM..
# 2  
Old 11-07-2012
I am afraid people won't be able to help much if you don't give an example of the contend of "server.list" & "datafile" files
# 3  
Old 11-07-2012
serverlist contains host names:

Code:
skysmart-01.sky.net
skysmart-02.sky.net


datefile contains:

Code:
[1351987200] LOG ROTATION: DAILY
[1351987200] LOG VERSION: 2.0
[1351987200] CURRENT HOST STATE: 10.20.20.20;UP;HARD;1;PING OK - Packet loss = 0%, RTA = 3.81 ms
[1351987200] CURRENT HOST STATE: skysmart-01.sky.net;UP;HARD;1;PING OK - Packet loss = 0%, RTA = 11.52 ms
[1351987200] CURRENT HOST STATE: skysmart-01.sky.net;UP;HARD;1;PING OK - Packet loss = 0%, RTA = 8.96 ms

What i want is an output like this:

Code:
Wed Nov  7 19:28:46 UTC 2012 [1352267653] SERVICE NOTIFICATION: nagiosadmin skysmart-01.sky.net ....

# 4  
Old 11-07-2012
Try:
Code:
echo "${line}"

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 11-07-2012
Quote:
Originally Posted by Scrutinizer
Try:
Code:
echo "${line}"

lol wow. i spent all day on this, and the fix is pretty simple.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Question related to grep

We have huge file with control A as delimiter. Somehow one record is corrupted. This time i figured it out using ETL graph. If future , how to print only bad record. Example Correct record:... (2 Replies)
Discussion started by: srikanth38
2 Replies

2. Shell Programming and Scripting

awk related question (for loop) difficult scenario

VARA='hello|welcome|gone|fantastic|superb|nicecar' if VARA contains a pipe "|", i want the contents of VARA to be tranformed to: VARA="(hello) (welcome) (gone) (fantastic) (superb) (nicecar)" so that, when i echo the contents of $VARA like this: echo "$VARA" or like this: print... (8 Replies)
Discussion started by: SkySmart
8 Replies

3. UNIX for Dummies Questions & Answers

Question related to 'ps'

If I run a script called 'abc.sh' and then execute the following : ps -ef | grep 'abc.sh' I always get two rows of output, one for the executing script, and the other for the grep command that I have triggered after the pipe. Questions: Why does the second row turn up in the results. My... (10 Replies)
Discussion started by: jawsnnn
10 Replies

4. Shell Programming and Scripting

Perl related question

hi, iam perl begginer,i have written the program #!/usr/bin/perl #use warnings; use strict; print "Enter the name:","\n"; my $name=<STDIN>; my %hash=(siva => "9902774481", dev => "9916391244", venky => "9440506760", manohar => "9440232695" ); print "$name no is:... (5 Replies)
Discussion started by: siva.hardwork
5 Replies

5. Shell Programming and Scripting

awk related question

awk "/^<Mar 31, 2012 : /,0" /app/blah.log can someone please help me figure out why the above command isn't pulling anything out from the log? basically, i want it to pull out all records, from the very first line that starts with the date "Mar 31, 2012" and that also has a time immediately... (4 Replies)
Discussion started by: SkySmart
4 Replies

6. Shell Programming and Scripting

having df command related question

Hi All, When i have run the below command its showing 90% which is critical for production. for this i need the answer of some below question please help me for that. 1) i want to delete some unwanted files. how can i know the unwanted files ?Is it there any way of knowing this?? 2)and... (2 Replies)
Discussion started by: aish11
2 Replies

7. Shell Programming and Scripting

Question related to sed or awk or perl

Hi All, I have a big file of 100,000 lines with the following format: 1,736870,736870,1,2,5,547,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445 1,881246,881246,1,2,6,402,1253889535,1253889775,240,30,152.163.141.8,US,0,00,-g 1253889445... (4 Replies)
Discussion started by: toms
4 Replies

8. Solaris

RBAC related question.....

I am referring Bill Calkins(SCSA exam prep) for RBAC..actually i wanted to make a normal user to get the privilege to run a command through authorization, not through profile files... This is the exact steps given by Bill calkins.. 1.roleadd -m -d /export/home/adminusr -c... (11 Replies)
Discussion started by: saagar
11 Replies

9. UNIX for Advanced & Expert Users

One Question related to alias

Hello, I have created following alias in csh lab 'rlogin -l user23 complab23' but problem is complab23 does not allow automatic login by checking .rhosts file. So after typing lab on command line I have to type complicate password and if wrong password is typed thrice then account gets... (4 Replies)
Discussion started by: neerajrathi2
4 Replies

10. UNIX for Dummies Questions & Answers

A Question related to the net

well, I was suggested to remove the contents of the cache as i get out of the browser netscape from the .netscape folder. is that really necessary? if so what are the rest to be done? can anybody please tell me?:rolleyes: (8 Replies)
Discussion started by: sskb
8 Replies
Login or Register to Ask a Question