Taking a particular attribute's value in a file...

HI,
Iam new to scripting..I need some guidance for invoking the following logic..
My input file contains

  Event Time = Thu, Nov 6, 2008 08:41:56 AM
                         Probable Cause = UnspecifiedReason
                      Specific Problems = BTS down due to Tx
                                 Domain = Domain 00-00-00-00-00-00-00-A8-1D-4E-91-5D-4C-75:.gp.dm.GSM_dm
                           Alarm Origin = IncomingAlarm
                     Perceived Severity = Critical
                        Additional Text = "NeType: BSC6000| NeLocation: | vendor: | neName: SVHBS150| alarmName: FUEL LEVEL 
                                          LOW| alarmLocation: Site No.=1188,Board Type=70,Board No.=0,PassNo=255,SubLink 
                                          No.=255,CellNo=65535,Site Type=16,RackNo=255,BoxNo=255,SlotNo=255| appendInfo:  
                                          MOI=DC=www.huawei.com , SubNetwork=1 , ManagedElement=7 , BssFunction=0 , 
                                          BtsSiteMgr=1188 
                                          NotificationId=4900 
                                          SpecificProblem=6448 
                                          <ALM_ID>580757<ALM_ID>"
                      Original Severity = Critical
                    Original Event Time = Thu, Nov 6, 2008 08:41:56 AM
                    Problem Occurrences = 1 Problems

Now from the above i need following output:

Event Time = Thu, Nov 6, 2008 08:41:56 AM

output of this should be

eventTime=06-11-2008-08-41..
Additional Text = "NeType: BSC6000| NeLocation: | vendor: | neName: SVHBS150| alarmName: FUEL LEVEL 
                                          LOW| alarmLocation: Site No.=1188,Board Type=70,Board No.=0,PassNo=255,SubLink 
                                          No.=255,CellNo=65535,Site Type=16,RackNo=255,BoxNo=255,SlotNo=255| appendInfo:  
                                          MOI=DC=www.huawei.com , SubNetwork=1 , ManagedElement=7 , BssFunction=0 , 
                                          BtsSiteMgr=1188 
                                          NotificationId=4900 
                                          SpecificProblem=6448 
                                          <ALM_ID>580757<ALM_ID>"

IN th einput additional text is containing n number of lines
if iam grepping to display the output only it is giving this value...

"NeType: BSC6000| NeLocation: | vendor: | neName:

,so I need to take the entire value of Additional text and whenever it has newline ~nl~ has to be appended i.e o/p should be

NeType: BSC6000| NeLocation: | vendor: | neName: SVHBS150|~nl~alarmName: FUEL LEVEL~nl~  LOW| alarmLocation: Site ~nl~No.=1188,Board Type=70,Board No.=0,PassNo=255,SubLink 
                                         ~nl~ No.=255,CellNo=65535,Site ~nl~Type=16,RackNo=255,BoxNo=255,SlotNo=255| appendInfo:  
                                       ~nl~   MOI=DC=www.huawei.com , ~nl~SubNetwork=1 , ManagedElement=7 , BssFunction=0 , 
                                         ~nl~ BtsSiteMgr=1188 
                                         ~nl~ NotificationId=4900 
                                          ~nl~SpecificProblem=6448 
                                          ~nl~<ALM_ID>580757<ALM_ID>
....

Can anyone help me out for the above scripting....Thanks

Edit: Please use code tags to make it readable. I added tags to make it as readable as possible :slight_smile:
LLB..

I did not follow your question completely but you could get part of your solution by doing something like:

awk '/Additional/,/ID/' file.name

BUt it didn't work well..
Let us complete one by one..
My input file format is
Event Time = Thu, Nov 6, 2008 08:41:56 AM
Output of the above should be
eventtime=06(DD)-11(MM)-2008(YYYY)-08(HH)-41(MM)
Can anyone guide me for doing scripting fo rthe above..

#!/bin/sh

date_var=`grep 'Event Time' a.txt | head -1 | cut -d= -f2`
date -d $date_var '+%d-%m-%Y-%H-%M'

Hi,
I tried but it is showing -d is not valid option...and hence it is not working..
Can u give any other solution..
Thanks,
Llb

What system are you running this on?

Thsi is my client's system where i can't do any modification..

This is HPUX system

Hi

Please try the below code ..
Here 'test' is the file which contains the entire text.

cat test | awk ' $0 ~ /Additional Text/ { print $0; getline;
while ( $0 !~ /Original Severity/ )
{
print $0;
getline;
}
}
'

The output of the program is --
Additional Text = "NeType: BSC6000| NeLocation: | vendor: | neName: SVHBS150| alarmName: FUEL LEVEL
LOW| alarmLocation: Site No.=1188,Board Type=70,Board No.=0,PassNo=255,SubLink
No.=255,CellNo=65535,Site Type=16,RackNo=255,BoxNo=255,SlotNo=255| appendInfo:
MOI=DC=www.huawei.com , SubNetwork=1 , ManagedElement=7 , BssFunction=0 ,
BtsSiteMgr=1188
NotificationId=4900
SpecificProblem=6448
<ALM_ID>580757<ALM_ID>"

Thanks a lot...It is really working fine..Also in this case i need the value after =....
Also Any suggestion for the timing format to be changed...

I did not get about which value after the = ... u need ..
Could you please explain tht ?

Hi
This is the script for date conversion -
File test contains the entire text.

cat test | awk -F ' ' ' $0 ~ /Event Time/ { printf $6 "-"; if ($0 ~ /Nov/ ) printf "11"; if ($0 ~ /Dec/ ) printf "12";
if ($0 ~ /Jan/ ) printf "1"; if ($0 ~ /Feb/ ) printf "2"; if ($0 ~ /Mar/ ) printf "3";
if ($0 ~ /Apr/ ) printf "4";if ($0 ~ /May/ ) printf "5"; if ($0 ~ /Jun/ ) printf "6"; if ($0 ~ /Jul/ ) printf "7";
if ($0 ~ /Aug/ ) printf "8"; if ($0 ~ /Sep/ ) printf "9"; if ($0 ~ /Oct/ ) printf "10";
printf "-" $7; printf "-" $8; }' | awk -F ':' ' { print $1"-"$2; }' | sed -e 's/,//g'

Output of the prog is --

6-11-2008-08-41

Let me know if you expect the same or something else ..

This is wha I expected..Awesome...
Thanks in Million boss...
Similarly for Additional text o/p , can i get the value i.e after equal to sign only...
Additional Text = "NeType: BSC6000| NeLocation: | vendor: | neName: SVHBS150| alarmName: FUEL LEVEL
LOW| alarmLocation: Site No.=1188,Board Type=70,Board No.=0,PassNo=255,SubLink
No.=255,CellNo=65535,Site Type=16,RackNo=255,BoxNo=255,SlotNo=255| appendInfo:
MOI=DC=www.huawei.com , SubNetwork=1 , ManagedElement=7 , BssFunction=0 ,
BtsSiteMgr=1188
NotificationId=4900
SpecificProblem=6448
<ALM_ID>580757<ALM_ID>"This is what o/p of addn. text is..
Now i need to get only this value:"NeType: BSC6000| NeLocation: | vendor: | neName: SVHBS150| alarmName: FUEL LEVEL
LOW| alarmLocation: Site No.=1188,Board Type=70,Board No.=0,PassNo=255,SubLink
No.=255,CellNo=65535,Site Type=16,RackNo=255,BoxNo=255,SlotNo=255| appendInfo:
MOI=DC=www.huawei.com , SubNetwork=1 , ManagedElement=7 , BssFunction=0 ,
BtsSiteMgr=1188
NotificationId=4900
SpecificProblem=6448
<ALM_ID>580757<ALM_ID>"
Thanks,
Llb..

I have just made a small addition to the previous code ..

cat test | awk ' $0 ~ /Additional Text/ { print $0; getline;
while ( $0 !~ /Original Severity/ )
{
print $0;
getline;
}
}
' | sed -e 's/Additional Text = //g'

The output of this will be the text after the =...

NeType: BSC6000| NeLocation: | vendor: | neName: SVHBS150| alarmName: FUEL LEVEL
LOW| alarmLocation: Site No.=1188,Board Type=70,Board No.=0,PassNo=255,SubLink
No.=255,CellNo=65535,Site Type=16,RackNo=255,BoxNo=255,SlotNo=255| appendInfo:
MOI=DC=www.huawei.com , SubNetwork=1 , ManagedElement=7 , BssFunction=0 ,
BtsSiteMgr=1188
NotificationId=4900
SpecificProblem=6448
<ALM_ID>580757<ALM_ID>"--I got this output-- Now if the char count is more than 160 the i have to truncate it from last until it is 160 characters...I tried sed command sed "s/^.\{160\}/d/g"...But it is removing 160 char and th remaning is 200+char....Since each time th enumber of character will differ i can't give a fixed value in the sed command....
Need your guidanc eagain in truncationg to 160 char...
Thanks,
LB...

You can use the below command to get the 1st 160 characters of the text . (test is the file which contains the text)

head -160c test

Note: the new line characters and spaces are also considered a part of the 160 characters here.

Hope this solves your query.

HI,
Still I didn't try that 160char option...
Meanwhile i had some simple issue which is taking more time...
if [ "$alarm_name" = "RECTIFIER MODULE FAIL" -o "$alarm_name" = "MAINS FAIL" -o "$alarm_name" = "BATTERY DISCONNECTED PRE ALARM" -o "$alarm_name" = "FUEL LEVEL LOW" ]; then
rT="BTS "$BTS_Name" is down due to "$alarm_name
echo $rT
else
echo "Alarmname for M2000 is not valid and henceforth SMS will not be written"
exit
fi
in the above code if there is no space between = in if cdn then it is giving o/p as whatever value is..ex:if it is Main low it is giving that o/p.It is not taking els epart.
If iam removing space between= in if cdn,it is taking only else part and displaying..
can anyone provide solution for above...ASAP..