Printing the lines which proceeds the particular string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing the lines which proceeds the particular string
# 1  
Old 11-17-2009
Printing the lines which proceeds the particular string

Hi,

We are facing some issues while finding the particular string.
Our file is:
Code:
 cat 1.txt
Node Name(s) [node01]
Preparation fragment

Partition: [Partition #1]
Transformation instance: [SQ_LOANS]
Transformation: [SQ_LOANS]
Applied rows: [101]
Affected rows: [101]
Rejected rows: [0]
Throughput(Rows/Sec): [104]
Throughput(Bytes/Sec): [0]
Last error code [0], message [No errors encountered.]


Partition: [Partition #1]
Transformation instance: [LOANS]
Transformation: [LOANS]
Applied rows: [15]
Affected rows: [15]
Rejected rows: [0]
Throughput(Rows/Sec): [987]
Throughput(Bytes/Sec): [0]
Last error code [0], message [No errors encountered.]

Now we just want "Applied rows" which belongs to only LOANS.
That is the output will be:
Code:
Transformation: [LOANS]
Applied rows: [15]

How can we grep only LOANS (not SQ_LOANS) from the file along with its Applied rows??

I have tried to create new file which will be having line number.Following are the commands which i tried:
Code:
cat -n 1.txt > 1_new.txt
val=`cat 1_new.txt | fgrep -w "LOANS' | fgrep -w "Transformation instance"`
new_val=`expr $val + 2`
cat 1_new.txt| grep $new_val

Any idea to achive this ?? Smilie Smilie

Thanks in Advance!!
# 2  
Old 11-17-2009
Code:
awk '/Transformation:/ && $2=="[LOANS]" {getline; print}' file

# 3  
Old 11-17-2009
Code:
$ awk '/Transformation: \[LOANS\]/,/Applied rows/' 1.txt
Transformation: [LOANS]
Applied rows: [15]

# 4  
Old 11-17-2009
MySQL

Hey!! thanks for the reply Smilie Smilie

Now its working fine... with just one command Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help in printing n number of lines if a search string matches in a file

Hi I have below script which is used to grep specific errors and if error string matches send an email alert. Script is working fine , however , i wish to print next 10 lines of the string match to get the details of error in the email alert Current code:- #!/bin/bash tail -Fn0 --retry... (2 Replies)
Discussion started by: neha0785
2 Replies

2. Shell Programming and Scripting

printing lines before and after a record

Hello Everyone, I want to print out the records after and before a certain record. I am able to figure out how to print that particular record but not the ones before and after. Looking for some advice Thank you (6 Replies)
Discussion started by: danish0909
6 Replies

3. Shell Programming and Scripting

Printing the lines of the string with highest value

Please help . The script need to first grep for all lines with "C:" as it contains a value Here the value is 0 1,00: This , is a good script c:0 and then give output of the lines with top 3 highest value for c: 1,00: This , is a nice script c:9999 1,00: This , is a... (3 Replies)
Discussion started by: necro98
3 Replies

4. Shell Programming and Scripting

Printing the lines that appear in an other file, and the three lines after them

Hi ! I need some help with a script I am writing. I am trying to compare two files, the first file being in this format : Header1 Text1-1 Text1-2 Text1-3 Header2 Text2-1 etc... For each header, I want to check if it appears in the second file, and if it is the case print the header... (4 Replies)
Discussion started by: jbi
4 Replies

5. Shell Programming and Scripting

grep on string and printing line after until another string has been found

Hello Everyone, I just started scripting this week. I have no background in programming or scripting. I'm working on a script to grep for a variable in a log file Heres what the log file looks like. The x's are all random clutter xxxxxxxxxxxxxxxxxxxxx START: xxxxxxxxxxxx... (7 Replies)
Discussion started by: rxc23816
7 Replies

6. Shell Programming and Scripting

Printing all lines before a specific string and a custom message 2 lines after

Hello all, I need to print all the lines before a specific string and print a custom message 2 lines after that. So far I have managed to print everything up the string, inclusively, but I can't figure out how to print the 2 lines after that and the custom message. My code thus far is:... (4 Replies)
Discussion started by: SEinT
4 Replies

7. Shell Programming and Scripting

Printing 10 lines above and below the search string: help needed

Hi, The below code will search a particular string(say false in this case) and return me 10 lines above and below the search string in a file. " awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print("***********************************");print;c=a;}b{r=$ 0}' b=10 a=10 s="false" " ... (5 Replies)
Discussion started by: vimalm22
5 Replies

8. Shell Programming and Scripting

printing lines to a file from a particular string

Hi, A very Good Evening to All, I am writing a script for my application. I have a file with 1000 lines. Among that 1000 lines i am searching for a particular string. And from that string i need to pull all the data in to a seperate file. For example the contents of my file is as below. ... (4 Replies)
Discussion started by: intiraju
4 Replies

9. Shell Programming and Scripting

Printing specified lines only

hi, i m having 2 files say F1 and F2. there are some joining conditions like: Column 4 from F1= Column 29 from F2; Column 10 from F1= Column 165 in F2; and if value in column 8 from F2='3' than i should get Column 4,5,8,10 from F1 and 29,165 from F2. I cant provide the files. but the... (4 Replies)
Discussion started by: Mohit623
4 Replies
Login or Register to Ask a Question