how to sort paragraphs by date within a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to sort paragraphs by date within a file
# 1  
Old 02-13-2008
Question how to sort paragraphs by date within a file

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

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
Smilie

! *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 Smilie
(date pattern=/07-12-17/)
i tried to use the sort -k but i coldnt understand the right pattern to use it
or I have to sort this date pattern by loops ?
cant understand
Smilie
# 2  
Old 02-13-2008
Duplicate post.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

2. Shell Programming and Scripting

file separated into paragraphs or pages

hi, i have file, file is separated into parahgraphs by these line(----------). i want to find out logId = string : "AIALARM", in each parahgraph or page if found then i want to cut next five lines.... ... (3 Replies)
Discussion started by: dodasajan
3 Replies

3. Shell Programming and Scripting

splitting a large text file into paragraphs

Hello all, newbie here. I've searched the forum and found many "how to split a text file" topics but none that are what I'm looking for. I have a large text file (~15 MB) in size. It contains a variable number of "paragraphs" (for lack of a better word) that are each of variable length. A... (3 Replies)
Discussion started by: lupin..the..3rd
3 Replies

4. Shell Programming and Scripting

shell script to sort entries in a file by date and time

Hello All, Need a shell script to sort entries in a file by date and time. Below are the entries in the file, i need to sort it first by the date and then time Note :- Date is in MM/DD/YY format and date comes as the 6th & time comes on 7th coloumns respectively. 150 pbnawldb001-b... (10 Replies)
Discussion started by: ajiwww
10 Replies

5. Shell Programming and Scripting

Sort content of text file based on date?

I now have a 230,000+ lines long text file formatted in segments like this: Is there a way to sort this file to have everything in chronological order, based on the date and time in the text? In this example, I would like the result to be: (19 Replies)
Discussion started by: KidCactus
19 Replies

6. Shell Programming and Scripting

how to filter out some paragraphs in a file

Hi, I am trying to filter out those paragraphs that contains 'CONNECT', 'alter system switch logfile'. That means say the input file is : ------------------------------------------------------- Wed Jun 7 00:32:31 2006 ACTION : 'CONNECT' CLIENT USER: prdadm CLIENT TERMINAL: Wed Jun 7... (7 Replies)
Discussion started by: cnlhap
7 Replies

7. Shell Programming and Scripting

How to sort a field in a file having date values

Hi All, I am having a pipe delimited file .In this file the 3rd column is having date values.I need to get the min date and max date from that file. I have used cut -d '|' test.dat -f 3|sort -u But it is not sorting the date .How to sort the date column using unix commands Thanks ... (4 Replies)
Discussion started by: risshanth
4 Replies

8. Shell Programming and Scripting

how to extract paragraphs from file in BASH script followed by prefix ! , !! and !!!

I]hi all i am in confusion since last 2 days :( i posted thraed yesterday and some friends did help but still i couldnt get solution to my problem let it be very clear i have a long log file of alkatel switch and i have to seperate the minor major and critical alarms shown by ! , !! and !!!... (6 Replies)
Discussion started by: nabmufti
6 Replies

9. AIX

loop through the directory for files and sort by date and process the first file

hello i have a requirement where i have a direcotry in which i get files in the format STOCKS.20080114.dat STOCKS.20080115.dat STOCKS.20080117.dat STOCKS.20080118.dat i need to loop through the directory and sort by create date descending order and i need to process the first file. ... (1 Reply)
Discussion started by: dsdev_123
1 Replies

10. Shell Programming and Scripting

sort a file by date using perl

Hello, do any body help me to sort a file by date using perl? thanks in advance Esham (4 Replies)
Discussion started by: esham
4 Replies
Login or Register to Ask a Question