![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
@ 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 |
|
||||
|
Hey ya this is working for the BSIC part well.....
---------- Post updated at 06:17 PM ---------- Previous update was at 05:50 PM ---------- Quote:
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 |
|
|||||
|
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
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|