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 03: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 05:09 AM
pattern matching and print with sed nymus7 Shell Programming and Scripting 2 04-14-2005 09:36 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-24-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 28
Thumbs up Script on pattern matching and print lines and export to excel

Hi Friends,

I am working on a script.. Looking forward for your expert help.....

My requirement is:

I have a text file where, need to search equip * RTF or end of line with RTF ,once this pattern is found then print 2nd line, 6th line, 7th line to a different file.
For Ex:

Code:
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
OutPut will be
Code:
BCCH 4 0 4 6 9 106 1353 75
NON_BCCH 4 0 4 6 9 106 1351 80
so on.. Thr wil be many lines matching equip 1 RTF...

Regards
Shalini

Last edited by Yogesh Sawant; 06-29-2009 at 04:48 AM.. Reason: added code tags
  #2 (permalink)  
Old 06-24-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
what have you tried till now??
I will give you some hint..
use sed there is an option called "n" and "N" read man page and give it a try...
  #3 (permalink)  
Old 06-24-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
there're a number of similar threads - please use the Search function first next time you're about to open a new thread.
Code:
nawk 'c&&c-- {if (c==5 ||c==2||c==1) printf $0 ((c==1)?ORS:OFS);next} /^equip.*RTF$/ {c=7}' myFile
  #4 (permalink)  
Old 06-25-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 28
Thanks a lot... It did work after i use the below line
Code:
nawk 'c&&c-- {if (c==5 ||c==1||c==0) printf $0 ((c==0)?ORS:OFS);next} /^*RTF$/ {c=7}' BSC01_CHARKOP.COMBINED > aa1
But output is:
Code:
BCCH 4 0 4 6 9 106 1351 77
BCCH 4 0 4 6 9 106 1352 68
NON_BCCH 4 0 4 6 9 106 1351 87
NON_BCCH 4 0 4 6 9 106 1351 113
NON_BCCH 4 0 4 6 9 106 1351 122
NON_BCCH 4 0 4 6 9 106 1352 112
NON_BCCH 4 0 4 6 9 106 1352 119
NON_BCCH 4 0 4 6 9 106 1352 124
NON_BCCH 4 0 4 6 9 106 1352 756
I wanted something like this :
Code:
BCCH-4 0 4 6 9 106 1351-77
BCCH-4 0 4 6 9 106 1352-68
NON_BCCH-4 0 4 6 9 106 1351-87-113-122
NON_BCCH-4 0 4 6 9 106 1352-112-119-124
Thanks and Regards
Shalini

Last edited by Yogesh Sawant; 06-29-2009 at 04:50 AM.. Reason: added code tags
  #5 (permalink)  
Old 06-25-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
Quote:
Originally Posted by shaliniyadav View Post
Thanks a lot... It did work after i use the below line
----------------------------------------------------------
nawk 'c&&c-- {if (c==5 ||c==1||c==0) printf $0 ((c==0)?ORS:OFS);next} /^*RTF$/ {c=7}' BSC01_CHARKOP.COMBINED > aa1
-----------------------------------------------------------

But output is:


BCCH 4 0 4 6 9 106 1351 77
BCCH 4 0 4 6 9 106 1352 68
NON_BCCH 4 0 4 6 9 106 1351 87
NON_BCCH 4 0 4 6 9 106 1351 113
NON_BCCH 4 0 4 6 9 106 1351 122
NON_BCCH 4 0 4 6 9 106 1352 112
NON_BCCH 4 0 4 6 9 106 1352 119
NON_BCCH 4 0 4 6 9 106 1352 124
NON_BCCH 4 0 4 6 9 106 1352 756

I wanted something like this :

BCCH-4 0 4 6 9 106 1351-77
BCCH-4 0 4 6 9 106 1352-68
NON_BCCH-4 0 4 6 9 106 1351-87-113-122
NON_BCCH-4 0 4 6 9 106 1352-112-119-124

Thanks and Regards
Shalini
This is not what you wanted originally.
Please provide a sample input that resulted in that/desired output.
Also, what have you tried to do yourself to achieve the desired output?
  #6 (permalink)  
Old 06-25-2009
shaliniyadav shaliniyadav is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 28
Hi,

Input is same...

Now that this output is generated need to just delete the occurances..
Considering same output
But output is:
Code:
BCCH 4 0 4 6 9 106 1351 77
BCCH 4 0 4 6 9 106 1352 68
NON_BCCH 4 0 4 6 9 106 1351 87
NON_BCCH 4 0 4 6 9 106 1351 113
NON_BCCH 4 0 4 6 9 106 1352 112
NON_BCCH 4 0 4 6 9 106 1351 122
NON_BCCH 4 0 4 6 9 106 1352 119
NON_BCCH 4 0 4 6 9 106 1352 124
NON_BCCH 4 0 4 6 9 106 1352 756
If you just check 3rd 4th 6th only last values are varrying.... So what i want is in same line it should be appended

Like
Non_BCCH 4 0 4 6 9 106 1351 87 113 122

thats it... Considering the last values in same line...

What i tried was:

By using below input
contents of file.txt:
TCS,1

TCS,2

TCS,3

TCS,4

CTS,1

CTS,2

CTS,3


O/P:
TCS, 1 2 3 4
CTS, 1 2 3

But i am not sure that al values wil be in continuous manner

considering

abc,1
abc,2
xyz,5
abc,4
i am not getting
Below code
awk -F, '
{
if(NR == 1)
printf("%s",$0);
else
{
if($1 != var)
{
printf("\n%s,%d",$1,$2);
}
else
printf(" %s",$2);
}
var = $1;
}' file.txt

Last edited by Yogesh Sawant; 06-29-2009 at 04:51 AM.. Reason: added code tags
  #7 (permalink)  
Old 06-25-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
no, the output you're quoting was not produced from the previously quoted input.
Please provide the original input resulted in the quoted output.
I think I know what you want - just need a sample input to test.
Sponsored Links
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 07:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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