Script on pattern matching and print lines and export to excel


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script on pattern matching and print lines and export to excel
# 1  
Old 06-24-2009
MySQL 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 05:48 AM.. Reason: added code tags
# 2  
Old 06-24-2009
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  
Old 06-24-2009
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  
Old 06-25-2009
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 05:50 AM.. Reason: added code tags
# 5  
Old 06-25-2009
Quote:
Originally Posted by shaliniyadav
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  
Old 06-25-2009
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 05:51 AM.. Reason: added code tags
# 7  
Old 06-25-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print lines after matching two pattern

would like to print everything after matching two patterns AAA and BBB. output : CCC ZZZ sample data : AAA BBB CCC ZZZ (4 Replies)
Discussion started by: jhonnyrip
4 Replies

2. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

3. Shell Programming and Scripting

Want to print out lines with a matching pattern from file

Hi all, I want to search for strings in file1 that can be found in file2 and print out the whole line when matching pattern is found. I have used the below command, but this is not working for me, because it is writing out only the matching patterns from file2, not the whole line. fgrep -o... (2 Replies)
Discussion started by: MonikaB
2 Replies

4. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

5. Shell Programming and Scripting

How to print all the lines after pattern matching?

I have a file that contains... Number -------------------- 1 2 3 4 i want to print all the numbers after the hyphen ... (6 Replies)
Discussion started by: ankitknit
6 Replies

6. Shell Programming and Scripting

print range of lines matching pattern and previous line

Hi all, on Solaris 10, I'd like to print a range of lines starting at pattern but also including the very first line before pattern. the following doesn't print the range starting at pattern and going down to the end of file: cat <my file> | sed -n -e '/<pattern>{x;p;}/' I need to include the... (1 Reply)
Discussion started by: siriche
1 Replies

7. Shell Programming and Scripting

perl script print the lines between two pattern

i have a file as below sample.pl parameter1 argument1 argument2 parameter2 I want out as below argument1 argument2 that is , i want to print all the lines between parameter1 & parameter 2. i tried with the following if($mystring =~ m/parameter1(.*?)parameter2/) (2 Replies)
Discussion started by: roopa
2 Replies

8. Shell Programming and Scripting

I want to print next 3 lines after pattern matching.

Dear Experts, I have file called file1 in which i am greping a pattern after that i want to next 3 lines when that pattern is matched. Ex:- file1 USA UK India Africa Hello Asia Europe Australia Hello Peter Robert Jo i want to next 3 lines after matching Hello... (12 Replies)
Discussion started by: naree
12 Replies

9. Shell Programming and Scripting

Perl script to match a pattern and print lines

Hi I have a file (say 'file1')and I want to search for a first occurence of pattern (say 'ERROR') and print ten lines in the file below pattern. I have to code it in PERL and I am using Solaris 5.9. I appreciate any help with code Thanks Ammu (6 Replies)
Discussion started by: ammu
6 Replies

10. Shell Programming and Scripting

Print block of lines matching a pattern

Hi :), I am using the script to search "MYPATTERN" in MYFILE and print that block of lines containing the pattern starting with HEADER upto FOOTER. But my problem is that at some occurrence my footer is different e.g. ";". How to modify the script so that MYPATTERN between HEADER and different... (1 Reply)
Discussion started by: vanand420
1 Replies
Login or Register to Ask a Question