LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-13-2008, 02:26 PM   #1
nabmufti
LQ Newbie
 
Registered: Feb 2008
Posts: 13

Rep: Reputation: 0
Question check


hi all
i want help in sortng date in paragraphs within file ,
i want to ask as if there any option to sort a certain pattern of file not the rest of file.i.e the data of file become sorted with respect to date
i have a log file as follows

!! *A0628/081 /08-01-10/13 H 52/N=5524/TYP=INC/CAT=ID/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 13/AGEO=BAGRIAN -B01
/TEXAL=FIRE DETECT FAIL
!! *A0628/320 /08-01-15/14 H 33/N=7444/TYP=COM/CAT=ID/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 2/AGEO=CONTAIN2-B01
/TEXAL=FAULTY UNIT/COMPL.INF:
* #F0612/T11F14/NCEN=MULCT /08-01-30/11 H 41/NAM=ODCAB /TDA=0001
/N=7444/NIV=2/ENS=006/SENS=016-000-000/P='0018'H/CN=05
/EM: AFUR =URAD- 2


!! *A0628/538 /07-12-17/15 H 52/N=7576/TYP=ICT/CAT=ID/EVENT=MAL
/NCEN=MULCT /AM =SMTA1/AGEO=S1-TR01-B03-A085-R000
/TEXAL=LCL MFM SYN/COMPL.INF:
/AF=URMA1
/ ICTRQ AGCA=S1-TR01-B03-A085-R133
/AMET=01-26-03
/AFLR=217-06/CRC=NACT
!!! *A0628/294 /07-12-17/15 H 46/N=7512/TYP=SRE/CAT=IM/EVENT=MAL
/NCEN=MULCT /OBJCT=PS/AGEO=CDC
/TEXAL=SP INACCESSIBLE/COMPL.INF:
/PS =00009999/TYR=RN


!! *A0628/361 /07-12-17/15 H 46/N=7513/TYP=COM/CAT=ID/EVENT=MAL
/NCEN=MULCT /AM =SMMA/AGEO=S1-TR02-B05-A109-R000
/TEXAL=SAI-HARDWARE/COMPL.INF:
/N=3485/ALARMA MATERIAL /R=00000/CU1A
/CB 200 BLOS
! *A0628/359 /07-12-17/15 H 46/N=7514/TYP=COM/CAT=SI/EVENT=MAL
/NCEN=MULCT /AM =SMMA/AGEO=S1-TR02-B05-A109-R000
/TEXAL=SAI-SOFTWARE/COMPL.INF:
/N=4543/ABNT X25 INDISPO. /R=00083/CU1A
/SNPA=A13381/PHYSLINE=LIGP13F1


!!! *A0628/080 /08-01-13/07 H 30/N=6540/TYP=INC/CAT=IM/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 10/AGEO=RANGPUR -B01
/TEXAL=FIRE
!! *A0628/081 /07-12-29/16 H 22/N=5052/TYP=INC/CAT=ID/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 12/AGEO=KHOTYWAL-B01
/TEXAL=FIRE DETECT FAIL
!! *A0628/081 /08-01-10/13 H 52/N=5526/TYP=INC/CAT=ID/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 9/AGEO=BASTGLZR-B01
/TEXAL=FIRE DETECT FAIL


!!! *A0628/080 /08-01-10/13 H 52/N=5527/TYP=INC/CAT=IM/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 7/AGEO=ADABOSAN-B01
/TEXAL=FIRE
!!! *A0628/087 /08-01-16/01 H 28/N=7648/TYP=CLI/CAT=IM/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 10/AGEO=RANGPUR -B01

i want to extract the date , time , NCEN , EVENT , TAXAL & AGEO
i used the code following

[code:]
#!/bin/bash
sed '/^!/i\
' log | sed -n -e '/^!!! /,/^$/w critical.log' -e '/^!! /,/^$/w major.log' -e'/^! /,/^$/w minor.log'
awk 'BEGIN {FS="/"; RS=""} { printf "%s/%s/%s/\n%s\n%s\n%s\n%s/%s\n\n", $1, $3, $4, $10, $12, $8, $14, $15}' minor.log

exit 0
[/code]
this code does seperate the paragraphs follwing ! , !! , !!! (i.e. minor , major & critical alarms of the log file respectively ,in their respective log files i.e. minor.log ,major.log & critical.log )
and 'awk' gives me output as following

! *A0628/07-12-17/15 H 58/
NCEN=MULCT
AGEO=S1-TR01-B03-A085-R000
EVENT=MAL
TEXAL=AIS/COMPL.INF:/ /AF=URMA1

but i want the output to be sorted by date
(date pattern=/07-12-17/)
i tried to use the sort -k but i coldnt understand the right pattern to use it
i tried to sort the date pattern by reg exp and to some extent i suceeded by i ca only compare two dated i couldnt get the logic to make the loop to check each date in file and then puxh the latest date entry on top each time
i used the code

Code:
#!/bin/bash
read date1
read date2
a=${date1:0:2}
b=${date2:0:2}
if $a -ge $b
then
echo $a
elif $a -le $b
then echo $b
else
echo "sorry"
fi
exit 0
plz do it if u can or tell me the right way to go ahead
will u plz help me to solve my problem

Last edited by acid_kewpie; 02-13-2008 at 02:36 PM.
 
Old 02-15-2008, 06:41 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
If you remove some newlines 'awk 'BEGIN {FS="/"; RS=""} { printf "%s/%s/%s/%s%s%s%s/%s\n\n", $1, $3, $4, $10, $12, $8, $14, $15}' yourlogfile | sort -t '/' -k 2' it'll be sort of like using 'xargs' (not displaying everything correctly right now), which makes sorting a lot easier, then use sort with "-t" separator and "-k" 2nd field (though "-k" isn't vital here IIRC).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Disk check takes too long to check hemantm Linux - Hardware 16 12-22-2006 04:18 AM
Health Check / Server Completion Check Software? tells Linux - Enterprise 0 04-20-2006 11:03 AM
Partition check, check double check Vincentius Linux - General 0 12-25-2004 05:47 AM
Media Check= FAIL - MDSUMs Check out tgrier Linux - Newbie 6 11-26-2004 10:07 PM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration