The UNIX and Linux Forums  


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
I want to print next 3 lines after pattern matching. naree Shell Programming and Scripting 12 05-21-2009 04:04 AM
counting the lines matching a pattern, in between two pattern, and generate a tab d.chauliac Shell Programming and Scripting 4 03-19-2009 01:30 PM
Perl script to match a pattern and print lines ammu Shell Programming and Scripting 6 12-22-2008 04:26 AM
Print block of lines matching a pattern vanand420 Shell Programming and Scripting 1 09-29-2008 06:09 AM
pattern matching and print with sed nymus7 Shell Programming and Scripting 2 04-14-2005 10:36 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-30-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
Quote:
Originally Posted by vgersh99 View Post
Code:
nawk '
acell&&acell-- { if (!acell) bsic[idx]=$NF }
 
c&&c-- {
    if (c) v=$0
    else {
       if (NF>1) a[idx]=(idx in a)?a[idx] OFS v:v
       next
    }
}
$1=="add_cell" {
    acell=2;
    idx=""
    for(i=2;i<NF;i++) idx=(idx)? idx OFS $i : $i
    idxA[idx]
}
 
$0 in idxA { c=2 ;idx=$0;v=""}
 
END {
  for (i in idxA)
     print i OFS bsic[i] OFS a[i]
}' myFile

Hey this just cooool..... thnx a lot .....

---------- Post updated at 05:04 PM ---------- Previous update was at 01:42 PM ----------

Quote:
Originally Posted by vgersh99 View Post
Code:
nawk '
acell&&acell-- { if (!acell) bsic[idx]=$NF }
 
c&&c-- {
    if (c) v=$0
    else {
       if (NF>1) a[idx]=(idx in a)?a[idx] OFS v:v
       next
    }
}
$1=="add_cell" {
    acell=2;
    idx=""
    for(i=2;i<NF;i++) idx=(idx)? idx OFS $i : $i
    idxA[idx]
}
 
$0 in idxA { c=2 ;idx=$0;v=""}
 
END {
  for (i in idxA)
     print i OFS bsic[i] OFS a[i]
}' myFile
HI, This covers the second requirement also , now last thing would be to retrive last one value... from the data as below:

InputFile:
add_cell 4 0 4 6 9 106 1311 2
frequency_type = 1
bsic = 2Ah
wait_indication_parameters = 10
ccch_conf = 0
add_cell 4 0 4 6 9 106 1312 2
frequency_type = 1
bsic = 3Ah
wait_indication_parameters = 10
ccch_conf = 0
equip 1 RTF
FULL
BCCH
0 0
0
4 0 4 6 9 106 1311
69
255 255 255 255 255 255 255 255
equip 1 RTF
FULL
BCCH
1 0
0
4 0 4 6 9 106 1312
77
255 255 255 255 255 255 255 255
equip 1 RTF
FULL
NON_BCCH
0 2
0
4 0 4 6 9 106 1311
82
0 0 0 0 0 0 0 0
chg_element hopping_systems_enabled,0 1 2 cell_number = 4 0 4 6 9 106 1312
chg_element hopping_systems_enabled,1 1 2 cell_number = 4 0 4 6 9 106 1312
chg_element hopping_systems_hsn,0 45 2 cell_number = 4 0 4 6 9 106 1311
chg_element hopping_systems_hsn,1 38 2 cell_number = 4 0 4 6 9 106 1311

chg_hop_params cell_number = 4 0 4 6 9 106 1311
0
1
1
80 82 119
45
chg_hop_params cell_number = 4 0 4 6 9 106 1311
1
1
1
869 873
38

4 0 4 6 9 106 1311
1
1
4

4 0 4 6 9 106 1312
2
1
4

Output should be:
4 0 4 6 9 106 1311 2Ah 69 82 45 38
4 0 4 6 9 106 1312 3Ah 77


These 45 and 38 can be taken from any line which is given in red in above input file,on basis of hopping system or cell number

Really your help is appreciated...... Also plz expl me the logic behind the code to learn....
  #2 (permalink)  
Old 06-30-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
nawk '
acell&&acell-- {
    if (!acell)  bsic[idx]=$NF
}

ahop&&ahop-- {
    if (!ahop) a[idx]=(idx in a)?a[idx] OFS $0:$0
}

c&&c-- {
    if (c) v=$0
    else {
       if (NF>1) a[idx]=(idx in a)?a[idx] OFS v:v
       next
    }
}
$1=="add_cell" {
    acell=2;
    idx=""
    for(i=2;i<NF;i++) idx=(idx)? idx OFS $i : $i
    idxA[idx]
}

$1 == "chg_hop_params" {
    split($0, hopA, " = ")
    idx=hopA[2]
    ahop=5
    next
}

$0 in idxA { c=2 ;idx=$0;v=""}

END {
  for (i in idxA)
     print i OFS bsic[i] OFS a[i]
}' myFile

  #3 (permalink)  
Old 07-08-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
Unhappy

Quote:
Originally Posted by vgersh99 View Post
Code:
nawk '
acell&&acell-- {
    if (!acell)  bsic[idx]=$NF
}
 
ahop&&ahop-- {
   if (!ahop) a[idx]=(idx in a)?a[idx] OFS $0:$0
}
 
c&&c-- {
    if (c) v=$0
    else {
       if (NF>1) a[idx]=(idx in a)?a[idx] OFS v:v
       next
    }
}
$1=="add_cell" {
    acell=2;
    idx=""
    for(i=2;i<NF;i++) idx=(idx)? idx OFS $i : $i
    idxA[idx]
}
 
$1 == "chg_hop_params" {
   split($0, hopA, " = ")
   idx=hopA[2]
   ahop=5
   next
}
 
$0 in idxA { c=2 ;idx=$0;v=""}
 
END {
  for (i in idxA)
     print i OFS bsic[i] OFS a[i]
}' myFile
I have a slight difference in the pattern:
Considering the same input as before:
InputFile:

Code:
add_cell 4 0 4 6 9 106 1311 2
frequency_type = 1
bsic = 2Ah
wait_indication_parameters = 10
ccch_conf = 0
add_cell 4 0 4 6 9 106 1312 2
frequency_type = 1
bsic = 3Ah
wait_indication_parameters = 10
ccch_conf = 0
equip 1 RTF
FULL
BCCH
0 0
0
4 0 4 6 9 106 1311
69
255 255 255 255 255 255 255 255
equip 1 RTF
FULL
BCCH
1 0
0
4 0 4 6 9 106 1312
77
255 255 255 255 255 255 255 255
equip 1 RTF
FULL
NON_BCCH
0 2
0
4 0 4 6 9 106 1311
82
0 0 0 0 0 0 0 0
chg_element hopping_systems_enabled,0 1 2 cell_number = 4 0 4 6 9 106 1312
chg_element hopping_systems_enabled,1 1 2 cell_number = 4 0 4 6 9 106 1312
chg_element hopping_systems_hsn,0 45 2 cell_number = 4 0 4 6 9 106 1311
chg_element hopping_systems_hsn,1 38 2 cell_number = 4 0 4 6 9 106 1311

chg_hop_params cell_number = 4 0 4 6 9 106 1311
0
1
1
82 119
45
chg_hop_params cell_number = 4 0 4 6 9 106 1311
1
1
1
869 873
38

4 0 4 6 9 106 1311
1
1
4

4 0 4 6 9 106 1312
2
1
4



Output should be:
4 0 4 6 9 106 1311-2Ah-69-82 119-45-868 867-38
4 0 4 6 9 106 1312-3Ah-77


Just to explain if too confusing...

< 4 0 4 6 9 106 1311> -- Cell Number our Unique key
<2Ah> -- BSIC
<69> --(Next string after the Key if 4th line from this would be BCCH)
<82 119> --4th Line of Chg_hop_params
<45> --5th Line of Chg_hop_params

Let me know if its going above head.... Looking forward for your help

Last edited by vgersh99; 07-08-2009 at 08:14 AM..
Bits Awarded / Charged to shaliniyadav for this Post
Date User Comment Amount
07-08-2009 vgersh99 added code tags - charged 10K bits -10,000
  #4 (permalink)  
Old 07-08-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by shaliniyadav View Post
I have a slight difference in the pattern:
Considering the same input as before:
InputFile:

Code:
add_cell 4 0 4 6 9 106 1311 2
frequency_type = 1
bsic = 2Ah
wait_indication_parameters = 10
ccch_conf = 0
add_cell 4 0 4 6 9 106 1312 2
frequency_type = 1
bsic = 3Ah
wait_indication_parameters = 10
ccch_conf = 0
equip 1 RTF
FULL
BCCH
0 0
0
4 0 4 6 9 106 1311
69
255 255 255 255 255 255 255 255
equip 1 RTF
FULL
BCCH
1 0
0
4 0 4 6 9 106 1312
77
255 255 255 255 255 255 255 255
equip 1 RTF
FULL
NON_BCCH
0 2
0
4 0 4 6 9 106 1311
82
0 0 0 0 0 0 0 0
chg_element hopping_systems_enabled,0 1 2 cell_number = 4 0 4 6 9 106 1312
chg_element hopping_systems_enabled,1 1 2 cell_number = 4 0 4 6 9 106 1312
chg_element hopping_systems_hsn,0 45 2 cell_number = 4 0 4 6 9 106 1311
chg_element hopping_systems_hsn,1 38 2 cell_number = 4 0 4 6 9 106 1311

chg_hop_params cell_number = 4 0 4 6 9 106 1311
0
1
1
82 119
45
chg_hop_params cell_number = 4 0 4 6 9 106 1311
1
1
1
869 873
38

4 0 4 6 9 106 1311
1
1
4

4 0 4 6 9 106 1312
2
1
4



Output should be:
4 0 4 6 9 106 1311-2Ah-69-82 119-45-868 867-38
4 0 4 6 9 106 1312-3Ah-77


Just to explain if too confusing...

< 4 0 4 6 9 106 1311> -- Cell Number our Unique key
<2Ah> -- BSIC
<69> --(Next string after the Key if 4th line from this would be BCCH)
<82 119> --4th Line of Chg_hop_params
<45> --5th Line of Chg_hop_params

Let me know if its going above head.... Looking forward for your help
I don't understand how you got '119-45-868 867-38' from the given sample input.
Also, what changes have you tried yourself? We're on the THIRD page of this thread - you should be able make some minor modifications to the code.
  #5 (permalink)  
Old 07-08-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
Quote:
Originally Posted by vgersh99 View Post
I don't understand how you got '119-45-868 867-38' from the given sample input.
Also, what changes have you tried yourself? We're on the THIRD page of this thread - you should be able make some minor modifications to the code.
Im sorry about that...
Output would be:

Output should be:
4 0 4 6 9 106 1311-2Ah-69-82 119-45-869 873-38
4 0 4 6 9 106 1312-3Ah-77


are from the below lines in the input:

chg_hop_params cell_number = 4 0 4 6 9 106 1311
0
1
1
82 119
45
chg_hop_params cell_number = 4 0 4 6 9 106 1311
1
1
1
869 873
38
  #6 (permalink)  
Old 06-30-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
@vgresh99

Thanks a lots...... Really helpful for me......
  #7 (permalink)  
Old 07-08-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
something to start with - good luck!

Code:
BEGIN {
  SEPdash="-"
}
acell&&acell-- {
    if (!acell)  bsic[idx]=$NF
}

ahop&&ahop-- {
    if (ahop==1) hopv=$NF
    if (!ahop) a[idx]=(idx in a)?a[idx] OFS hopv SEPdash $0:hopv SEPdash $0
}

c&&c-- {
    if (c) v=$0
    else {
       if (NF>1) a[idx]=(idx in a)?a[idx] SEPdash v:v
       next
    }
}
$1=="add_cell" {
    acell=2;
    idx=""
    for(i=2;i<NF;i++) idx=(idx)? idx OFS $i : $i
    idxA[idx]
}

$1 == "chg_hop_params" {
    split($0, hopA, " = ")
    idx=hopA[2]
    ahop=5
    next
}

$0 in idxA { c=2 ;idx=$0;v=""}

END {
  for (i in idxA)
     print i SEPdash bsic[i] SEPdash a[i]
}

Reply

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 02:17 AM.


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