The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Join Date: Jun 2009
Posts: 30
Actually input is first thing what i have posted-----
equip 1 RTF
FULL
BCCH
2 0
0
4 0 4 6 9 106 1353
75
255 255 255 255 255 255 255 255
5 5 5 5 5 5 5 5
0
2
0
0
3
3
0
equip 2 RTF
FULL
NON_BCCH
0 1
0
4 0 4 6 9 106 1351
80
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
0
0
2
1
0
1
0
equip 2 RTF
FULL
NON_BCCH
0 1
0
4 0 4 6 9 106 1352
80
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
0
0
2
1
0
1
0
equip 2 RTF
FULL
NON_BCCH
0 1
0
4 0 4 6 9 106 1351
89
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
0
0
2
1
0
1
0

So i have just split my requiremnts instead of directly getting used below line as suggested by you :
Code:
nawk 'c&&c-- {if (c==1||c==0) printf $0 ((c==0)?ORS:OFS);next} /^*RTF$/ {c=6}' myFile
then got output:
Code:
4 0 4 6 9 106 1353 75
4 0 4 6 9 106 1351 80
4 0 4 6 9 106 1352 80
4 0 4 6 9 106 1351 89
So now next task would be to consider this temp output and get the below format:
Code:
4 0 4 6 9 106 1353 75
4 0 4 6 9 106 1351 80 89
4 0 4 6 9 106 1352 80
Hope this clarifies.....


Last edited by Yogesh Sawant; 06-29-2009 at 06:07 AM.. Reason: added code tags
  #2 (permalink)  
Old 06-29-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
Quote:
Originally Posted by shaliniyadav View Post
Actually input is first thing what i have posted-----
equip 1 RTF
FULL
BCCH
...

So i have just split my requiremnts instead of directly getting used below line as suggested by you :
Code:
nawk 'c&&c-- {if (c==1||c==0) printf $0 ((c==0)?ORS:OFS);next} /^*RTF$/ {c=6}' myFile
then got output:
Code:
4 0 4 6 9 106 1353 75
4 0 4 6 9 106 1351 80
4 0 4 6 9 106 1352 80
4 0 4 6 9 106 1351 89
So now next task would be to consider this temp output and get the below format:
Code:
4 0 4 6 9 106 1353 75
4 0 4 6 9 106 1351 80 89
4 0 4 6 9 106 1352 80
Hope this clarifies.....



So, can we conclude that you have got this from your original input
Quote:
Code:
4 0 4 6 9 106 1353 75
4 0 4 6 9 106 1351 80
4 0 4 6 9 106 1352 80
4 0 4 6 9 106 1351 89
and now want your final output to be...
Quote:
Code:
4 0 4 6 9 106 1353 75
4 0 4 6 9 106 1351 80 89
4 0 4 6 9 106 1352 80
If yes...then probably we are close to helping you
  #3 (permalink)  
Old 06-29-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
@Rakesh
No actually...
Code:as quoted by you

4 0 4 6 9 106 1353 75
4 0 4 6 9 106 1351 80 89
4 0 4 6 9 106 1352 80
Is already met to get thm in this format using the below code
--------------------------------------

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


---------------------------------------
And consider this input 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_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

So if you see above code wil provide output as below:

4 0 4 6 9 106 1311 69 82
4 0 4 6 9 106 1312 77

But my requirement is :

4 0 4 6 9 106 1311 2AH 69 82 45 38
4 0 4 6 9 106 1312 3AH 77

Hope u got it , Let me know if any queries
  #4 (permalink)  
Old 06-29-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
Code:
sed -n '/RTF/ {n;n;h;n;n;n;H;n;H;x;s/\n/ /g;p;}' yourfile
  #5 (permalink)  
Old 06-29-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
@summer_cherry

actually if you see the requirement its different.. RTF is already met, I also want to include BSIC and add_Cel value.......
  #6 (permalink)  
Old 06-25-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Code:
nawk '
   c&&c-- {
       if (c==1||c==0) { 
          if (c!=0) 
             idx=(idx)?idx OFS $0:$0
          else 
            a[idx]=(idx in a)?a[idx] OFS $0:$0
       }
       next
    } 
   /^*RTF$/ {c=6;idx=""} 
  END { 
    for (i in a) 
       print i OFS a[i]
}' myFile
  #7 (permalink)  
Old 06-26-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 30
Hey this is coool.. Thanks a lot ....

---------- Post updated at 07:07 PM ---------- Previous update was at 06:21 PM ----------

@vgersh99

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


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

Hey The above piece of code is working perfectly fine when want to retrieve on basis of one pattern i.e RTF condering the below input as same before, can you help me with in cases of two or three patterns for example :

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

Considering this input, Output can we get it as below:

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

)))......... The first group of numbers is from Key: *RTF ,2nd Key is BSIC, 3rd Key is same *RTF...

Is this possible...?????
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:16 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