The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to filter out some paragraphs in a file cnlhap Shell Programming and Scripting 7 08-19-2008 03:03 PM
how to sort paragraphs by date within a file nabmufti Shell Programming and Scripting 1 02-13-2008 05:33 PM
Script that extract some lines from a file lookin into another heartwork Shell Programming and Scripting 7 01-25-2008 06:57 AM
How to extract output from a script to .xls file scriptlearner Shell Programming and Scripting 6 08-10-2007 02:34 AM
Script to Extract the line from File with specified offset thinakarmani UNIX for Advanced & Expert Users 5 05-04-2006 05:50 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-08-2008
nabmufti nabmufti is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 15
Question 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 !!! respectively

the file format is like this[/I]

>> ALAIL;

CMD ALAIL 06095 08-01-30 11-58-23
INP ALAIL 06095 08-01-30 11-58-23
OPTEX=



RES ALAIL 06095 08-01-30 11-58-24
CEN=1/08-01-30/11 H 58 MN 19/STORED ALARMS LIST
PROCESSING TPFFIR ACC


! *A0628/540 /07-12-17/15 H 58/N=7598/TYP=ICT/CAT=SI/EVENT=MAL
/NCEN=MULCT /AM =SMTA1/AGEO=S1-TR01-B03-A085-R000
/TEXAL=AIS/COMPL.INF:
/AF=URMA1
/ ICTRQ AGCA=S1-TR01-B03-A112-R065
/AMET=01-07-02
/AFLR=222-09/CRC=NACT
!!! *A0628/303 /07-12-17/15 H 46/N=7501/TYP=COM/CAT=IM/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 4/AGEO=BUDLASAN-B01
/TEXAL=SINGLE JUNCT/UT OOS/COMPL.INF:
/CN=3


!!! *A0628/306 /08-01-23/07 H 20/N=9619/TYP=COM/CAT=IM/EVENT=MAL
/NCEN=MULCT /AFCN =CNLM3-4/AGEO=MKRASHID-B02-A003
/TEXAL=CN ISOLATED
!!! *A0628/303 /07-12-17/15 H 46/N=7503/TYP=COM/CAT=IM/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 12/AGEO=KHOTYWAL-B01
/TEXAL=SINGLE JUNCT/UT OOS/COMPL.INF:
/CN=0
!!! *A0628/089 /08-01-29/22 H 14/N=1760/TYP=ENP/CAT=IM/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 11/AGEO=QADIRPUR-B01
/TEXAL=GENERATING UNIT


!! *A0628/320 /08-01-17/13 H 47/N=8062/TYP=COM/CAT=ID/EVENT=MAL
/NCEN=MULCT /AFUR =URAL- 15/AGEO=S1-TR01-B04
/TEXAL=FAULTY UNIT/COMPL.INF:
* #F0612/T11F14/NCEN=MULCT /08-01-30/11 H 33/NAM=ODCAB /TDA=0001
/N=7064/NIV=2/ENS=006/SENS=013-000-000/P='0228'H/CN=02/PAR='03'H
/EM: AFUR =URAL- 15
!!! *A0628/303 /07-12-17/15 H 46/N=7506/TYP=COM/CAT=IM/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 7/AGEO=ADABOSAN-B01
/TEXAL=SINGLE JUNCT/UT OOS/COMPL.INF:
/CN=2


!!! *A0628/303 /07-12-17/15 H 46/N=7507/TYP=COM/CAT=IM/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 11/AGEO=QADIRPUR-B01
/TEXAL=SINGLE JUNCT/UT OOS/COMPL.INF:
/CN=2
!! *A0628/320 /08-01-26/06 H 39/N=0566/TYP=COM/CAT=ID/EVENT=MAL
/NCEN=MULCT /AFUR =URAD- 14/AGEO=KHOKARAN-B01
/TEXAL=FAULTY UNIT/COMPL.INF:

how wil i extract these paragraphs of alarms in respective alarm file??
i need to extract this log on the basis of prefix ! , !! , !!!


i am using the code to take input from file into script as


Code:
#!/bin/bash
alarm= `cat ~/alkatel.txt`
echo $alarm | while read line
do 
{
echo $line
}done
i want to see this code in bash only not in perl and any othe language please do me this favor
  #2 (permalink)  
Old 02-08-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool A try with bash

rm old alarm* files
will read an input file called alarms
put any beginning undefined lines into alarm
read thru the file, and based on ! or !! or !!! determine output file
write line to case'd filename

Note: once an alarm file is set, everything will be written there until a new alarm file is calculated.



#! /bin/bash

rm alarm alarm1 alarm2 alarm3
al_fl="alarm"
while read alt
do
al_pr=$(echo $alt | cut -d" " -f1)
case "$al_pr"
in
'!') al_fl="alarm1";;
'!!') al_fl="alarm2";;
'!!!') al_fl="alarm3";;
*) ;;
esac
# echo "$al_pr" "$al_fl"
echo "$alt">>"$al_fl"
done < alarms
  #3 (permalink)  
Old 02-08-2008
nabmufti nabmufti is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 15
attention

is any one there to help me out
i am waiting since 2 days
  #4 (permalink)  
Old 02-08-2008
nabmufti nabmufti is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 15
Question

i am trying the code above

but the problem is this , i have to deal with a log file keeping alarms of dated dec,07-jan 08
i have to extract these alarms entry by entry ,along with the contents it have ,to their respective files
(example of file given above)

i must have to take input from a file and then sort it and redirect respective paragraghs of log to that particular file e.g. ! to minor alarm file and so

i havnt successful in acheiving input from file and to sort by !!! , !! and !.

will u plz revise your script.
  #5 (permalink)  
Old 02-08-2008
nabmufti nabmufti is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 15
in short i wnt to extract paragraphs from a file by prefix ! , !! & !!!
thanx
  #6 (permalink)  
Old 02-09-2008
nabmufti nabmufti is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 15
Question any one can do it???

plz help me to come to solution of my problem
i want to extract paragraphs line following prefix ! , !! and !!!
i tried so mant times but i coldnt do it
file sample is in given above thraed
  #7 (permalink)  
Old 02-09-2008
H2OBoodle H2OBoodle is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 18
How about using something like this to extract all paragraphs with the !'s until a blank line or the next line that starts with a "!"?

sed -n '/^!!![^!]/,/[^$|^!]/p' # !!!
sed -n '/^!![^!]/,/[^$|^!]/p' # !!
sed -n '/^![^!]/,/[^$|^!]/p' # !

These should get your individual paragraphs.

Last edited by H2OBoodle; 02-09-2008 at 09:57 PM.. Reason: Simplified the start address
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0