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-26-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Yes, it's possible - give it a shot.
  #2 (permalink)  
Old 06-29-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
Hey!!.. I have been trying but not succeeded... See the requirement: Its like need to print the data which is in same line as searching pattern........... Please help in this regard...
  #3 (permalink)  
Old 06-29-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by shaliniyadav View Post
Hey!!.. I have been trying but not succeeded... See the requirement: Its like need to print the data which is in same line as searching pattern........... Please help in this regard...
Could you show exactly where you're stuck?
  #4 (permalink)  
Old 06-29-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
@ vgersh99

Just considering to retrieve 2 lines BSIC line and add_Cell line.

---------
nawk '
c&&c-- {
if (c==2 || c==0) {
if (c!=0)
idx=(idx)?idx OFS $0:$0
else
a[idx]=(idx in a)?a[idx] OFS $0:$0
}
next
}
/^add_cell*/ {c=2;idx=""}
END {
for (i in a)
print i OFS a[i]
}' inputfile

------------------------

This is printing only below output:

bsic = 2Ah
bsic = 3Ah

and not wid add_cell
  #5 (permalink)  
Old 06-29-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
here's something to start with:

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

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

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

  #6 (permalink)  
Old 06-29-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
Hey ya this is working for the BSIC part well.....

---------- Post updated at 06:17 PM ---------- Previous update was at 05:50 PM ----------

Quote:
Originally Posted by vgersh99 View Post
here's something to start with:

Code:
nawk '
acell&&acell-- { if (acell==0) bsic[idx]=$NF }
 
c&&c-- {
    if (!c) {
       a[idx]=(idx in a)?a[idx] OFS $0:$0
       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=1 ;idx=$0}
 
END {
  for (i in idxA)
     print i OFS bsic[i] OFS a[i]
}' myFile
-------------------------------------

Thanks a lot for your support...I actually tested this code on my original file... Actually getting some extra data also which is not required.....

For ex:Considering the input i have provided i had chosen only required data... In the output for above code you wil fine this data have a look:

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_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

So output of your piece of code is :

4 0 4 6 9 106 1311 2Ah 69 82 1
4 0 4 6 9 106 1312 3Ah 77 2

Here 1 is not to be printed in our case..... Which is marked in red in inputFile as well as output


  #7 (permalink)  
Old 06-29-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

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

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

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 08:58 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