need help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help
# 1  
Old 06-21-2011
Error need help

Hi,
I am a new in shell scripting.

Problem is :- in .dat file there is N number of records. for Ex.
******Record Number [837]*******ugdRec1.ban : 0ugdRec1.bill_seq_no : 0ugdRec1.subscriber_no : ugdRec1.channel_seizure_dt : 110618090132ugdRec1.message_switch_id : 5402 ugdRec1.resource_no : ******Record Number [63]*******ugdRec1.ban : 0ugdRec1.bill_seq_no : 0ugdRec1.subscriber_no : ugdRec1.channel_seizure_dt : 20110618064544ugdRec1.message_switch_id : 5020 ugdRec1.resource_no :

I want to seach a string "[XXXX]" and print 7 line from string in log and check if ugdRec1.resource_no is null or not. if null send me a mail with Record number from file. I tried using sed but not any luck...
Note :- XXXX is vary. its digiti.e Record number.May be 2 digit or may be 5 digit.

Thanks in advanced,

Venum
# 2  
Old 06-21-2011
Post the file in code tag. so it is easy to read it.

is your grep supports -A option ?

Code:
 
grep -A 7 837 filename

# 3  
Old 06-21-2011
need help

hi itkamaraj,
I tried, but its not working.
$ grep -A 7 64 temp
grep: illegal option -- A
what i want, If "ugdRec1.resource_no" is null mean (colon( : ) and no number is present .i.e empty) then return that particular record.

******Record Number [837]*******ugdRec1.ban : 0ugdRec1.bill_seq_no : 0ugdRec1.subscriber_no : ugdRec1.channel_seizure_dt : 20110618090132ugdRec1.message_switch_id : 5402 ugdRec1.resource_no : ******Record Number [63]*******ugdRec1.ban : 0ugdRec1.bill_seq_no : 0ugdRec1.subscriber_no : ugdRec1.channel_seizure_dt : 20110618064544ugdRec1.message_switch_id : 5020 ugdRec1.resource_no :
# 4  
Old 06-21-2011
can you post your code (input file) inside the [code] tag

---------- Post updated at 12:42 PM ---------- Previous update was at 12:41 PM ----------

so, your inut file is like this ?

Code:
Record Number [837]*******ugdRec1.ban : 0ugdRec1.bill_seq_no : 0ugdRec1.subscriber_no : ugdRec1.channel_seizure_dt : 20110618090132ugdRec1.message_switch_id : 5402 ugdRec1.resource_no : ******
Record Number [63]*******ugdRec1.ban : 0ugdRec1.bill_seq_no : 0ugdRec1.subscriber_no : ugdRec1.channel_seizure_dt : 20110618064544ugdRec1.message_switch_id : 5020 ugdRec1.resource_no :
Record Number [837]*******ugdRec1.ban : 0ugdRec1.bill_seq_no : 0ugdRec1.subscriber_no : ugdRec1.channel_seizure_dt : 20110618090132ugdRec1.message_switch_id : 5402 ugdRec1.resource_no : ******
Record Number [63]*******ugdRec1.ban : 0ugdRec1.bill_seq_no : 0ugdRec1.subscriber_no : ugdRec1.channel_seizure_dt : 20110618064544ugdRec1.message_switch_id : 5020 ugdRec1.resource_no :
Record Number [837]*******ugdRec1.ban : 0ugdRec1.bill_seq_no : 0ugdRec1.subscriber_no : ugdRec1.channel_seizure_dt : 20110618090132ugdRec1.message_switch_id : 5402 ugdRec1.resource_no : ******
Record Number [63]*******ugdRec1.ban : 0ugdRec1.bill_seq_no : 0ugdRec1.subscriber_no : ugdRec1.channel_seizure_dt : 20110618064544ugdRec1.message_switch_id : 5020 ugdRec1.resource_no :
Record Number [837]*******ugdRec1.ban : 0ugdRec1.bill_seq_no : 0ugdRec1.subscriber_no : ugdRec1.channel_seizure_dt : 20110618090132ugdRec1.message_switch_id : 5402 ugdRec1.resource_no : ******
Record Number [63]*******ugdRec1.ban : 0ugdRec1.bill_seq_no : 0ugdRec1.subscriber_no : ugdRec1.channel_seizure_dt : 20110618064544ugdRec1.message_switch_id : 5020 ugdRec1.resource_no :

each record in single line ?

---------- Post updated at 12:43 PM ---------- Previous update was at 12:42 PM ----------

or like this ?

Code:
Record Number [837]*******
ugdRec1.ban : 
0ugdRec1.bill_seq_no : 
0ugdRec1.subscriber_no : 
ugdRec1.channel_seizure_dt : 20110618090132
ugdRec1.message_switch_id : 5402 
ugdRec1.resource_no : ******
Record Number [837]*******
ugdRec1.ban : 
0ugdRec1.bill_seq_no : 
0ugdRec1.subscriber_no : 
ugdRec1.channel_seizure_dt : 20110618090132
ugdRec1.message_switch_id : 5402 
ugdRec1.resource_no : ******

# 5  
Old 06-21-2011
Second one.....
# 6  
Old 06-21-2011
Code:
 
bash-3.00$ nawk '/Record/ {for (i=0;i<6;i++) { if(i==0){ record_name = $0 } getline;} indx_value=index($0,":"); val=substr($0,indx_value+1,length($0)); if (
length(val) == 0) printf ("%s\n",record_name);}' test
Record No :11

bash-3.00$ cat test
Record No :10
b
c
d
e
f
g:bcd
Record No :11
b
c
d
e
f
g:
Record No :12
b
c
d
e
f
g:bcd

# 7  
Old 06-21-2011
hi again,

I run the above command. but its will give me only 1 record.
Please check the below screen shot.

if (length(val) == 0) printf ("%s\n",record_name);}' temp.txt <

******Record Number [63]*******

I think, my console has limited buffer.
Please chk cmd....

awk '/Record/ {for (i=0;i<6;i++) { if(i==0){ record_name = $0 } getline;} indx_value=index($0,":"); val=substr($0,indx_value+1,length($0)); if (length(val) == 0) printf ("%s\n",record_name);}' temp.txt
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question