![]() |
|
|
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 |
|
|
|
||||
|
Quote:
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! |
|
||||
|
Quote:
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 |
|
||||
|
Quote:
test : syntax error at line 4: `}' unexpected |
|
|||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|