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 07-08-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
Quote:
Originally Posted by vgersh99 View Post
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]
}

test: BEGIN: not found
test: syntax error at line 4: `}' unexpected

........ Delimiter is not that important... I just used for better explaining the output.... Even to reduce the requirement.... Considering this:

Input:

Code:
chg_hop_params cell_number = 4 0 4 6 9 106 1351
0
1
1
80 82 119
45
chg_hop_params cell_number = 4 0 4 6 9 106 1351
1
1
1
869 873
38
 
chg_element hopping_support 1 1 cell_number = 4 0 4 6 9 106 1352
chg_element hopping_systems_enabled,0 1 1 cell_number = 4 0 4 6 9 106 1352
chg_element hopping_systems_enabled,1 1 1 cell_number = 4 0 4 6 9 106 1352
chg_element hopping_systems_hsn,0 45 1 cell_number = 4 0 4 6 9 106 1352
chg_element hopping_systems_hsn,1 38 1 cell_number = 4 0 4 6 9 106 1352
chg_hop_params cell_number = 4 0 4 6 9 106 1352
0
1
1
87 112 122
45
chg_hop_params cell_number = 4 0 4 6 9 106 1352
1
1
1
745 752 754 871
38

Output:


Code:
4 0 4 6 9 106 1351 80 82 119 45 869 873 45
4 0 4 6 9 106 1352 87 112 122 45 745 752 754 871 38


Last edited by vgersh99; 07-08-2009 at 09:06 AM.. Reason: code tags, PLEASE!
  #2 (permalink)  
Old 07-08-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
Quote:
Originally Posted by shaliniyadav View Post
test: BEGIN: not found
test: syntax error at line 4: `}' unexpected

........ Delimiter is not that important... I just used for better explaining the output.... Even to reduce the requirement.... Considering this:

Input:

Code:
chg_hop_params cell_number = 4 0 4 6 9 106 1351
0
1
1
80 82 119
45
chg_hop_params cell_number = 4 0 4 6 9 106 1351
1
1
1
869 873
38
 
chg_element hopping_support 1 1 cell_number = 4 0 4 6 9 106 1352
chg_element hopping_systems_enabled,0 1 1 cell_number = 4 0 4 6 9 106 1352
chg_element hopping_systems_enabled,1 1 1 cell_number = 4 0 4 6 9 106 1352
chg_element hopping_systems_hsn,0 45 1 cell_number = 4 0 4 6 9 106 1352
chg_element hopping_systems_hsn,1 38 1 cell_number = 4 0 4 6 9 106 1352
chg_hop_params cell_number = 4 0 4 6 9 106 1352
0
1
1
87 112 122
45
chg_hop_params cell_number = 4 0 4 6 9 106 1352
1
1
1
745 752 754 871
38

Output:


Code:
4 0 4 6 9 106 1351 80 82 119 45 869 873 45
4 0 4 6 9 106 1352 87 112 122 45 745 752 754 871 38
I dont know why code not working here ...

But check this something which i have come with considering the above input

Code:
------------------------------------------
awk -F" " '
{
if($1=="chg_hop_params")
{
printf("\n%s",$0);
i=0;
}
else if(i>3 && i<6)
{
printf("-%s",$0);
}
i++;
}' input > temp1
sed 's/chg_hop_params cell_number = //g' temp1
rm temp1
---------------------------------------------

But this how i get:
Output:
4 0 4 6 9 106 1351 80 82 119 45
4 0 4 6 9 106 1351 869 873 45
4 0 4 6 9 106 1352 87 112 122 45
4 0 4 6 9 106 1352 745 752 754 871 38

Numbers in red should be appended in the first line itself.....

Last edited by shaliniyadav; 07-09-2009 at 02:13 AM.. Reason: Removed short words,abbreviations
  #3 (permalink)  
Old 07-08-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

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

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

ahop&&ahop-- {
    if (ahop==1) hopv=$0
    if (!ahop) a[idx]=(idx in a)?a[idx] OFS hopv OFS $0:hopv OFS $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]
}

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

Join Date: Jun 2009
Posts: 30
Quote:
Originally Posted by vgersh99 View Post
Code:
BEGIN {
  SEPdash="-"
}
acell&&acell-- {
    if (!acell)  bsic[idx]=$NF
}
 
ahop&&ahop-- {
    if (ahop==1) hopv=$0
    if (!ahop) a[idx]=(idx in a)?a[idx] OFS hopv OFS $0:hopv OFS $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]
}
test: BEGIN: not found
test : syntax error at line 4: `}' unexpected
  #5 (permalink)  
Old 07-08-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
works fine for me - as in the previous posts.

Code:
nawk -f myAwkFile.awk myInputFile

where myAwkFile.awk file contains the posted code.
  #6 (permalink)  
Old 07-08-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

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

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

ahop&&ahop-- {
    if (ahop==1) hopv=$0
    if (!ahop) a[idx]=(idx in a)?a[idx] OFS hopv OFS $0:hopv OFS $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]
}

sha.txt:

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


Code:
nawk -f sha.awk  sha.txt

produces:

Code:
4 0 4 6 9 106 1311 2Ah 69 82 82 119 45 869 873 38
4 0 4 6 9 106 1312 3Ah 77

  #7 (permalink)  
Old 07-09-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
Thanks a lot..
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 10:00 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