grep concatenation??


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep concatenation??
# 1  
Old 12-08-2011
grep concatenation??

So, I have huge results file and I need to extract two lines, so far I know that these two commands separately do what I need:

grep "Query=" results.out
grep "Sequence" -2 results.out

Now, I have no idea how to concatenate these results together so that every query matches up with their appropriate sequence. So the out put should be like:
Query= blablabla
Sequences bla bla bla:

BLAblabla

any help would be appreciated,
Thanks.
# 2  
Old 12-08-2011
On my system your second "grep" is a syntax error (thinks "-2" is a file).

Anyway, try egrep to extract the lines in the same order as the original file:
Code:
egrep "Query=|Sequence" results.out

# 3  
Old 12-08-2011
the grep "Sequence" -2 results.out ... prints only the second line from Sequence..

the egrep didn't work for me, as in my results file the actual sequence is based two lines after "Sequence".

I was thinking of making a script or something, but the idea died half way through..
# 4  
Old 12-08-2011
If that's not the data you have and not the output you want, show the data you have, and show the output you want. Until you do we're just guessing at what you want.
# 5  
Old 12-09-2011
The data I have is this:

Query= g1.t1 (1079 letters)


Database: Database10
21,546,138 sequences; 7,110,393,968 total letters


Searching..................................................done







Sequences producing significant alignments: Score E (bits) Value


BJgh3579 186 3e-44


>BJgh3579 Length = 1032


Score = 186 bits (472), Expect = 3e-44, Method: Compositional matrix adjust.


.....
So the red lines are the ones I need, I can get them separately by the codes above, but together in line I have no idea how to get them.
# 6  
Old 12-09-2011
You can't tell grep to print a line by matching the line above it. grep has no memory. grep just matches lines.

working on something in awk.

---------- Post updated at 09:32 AM ---------- Previous update was at 09:30 AM ----------

Code:
$ awk '/Query=/;/Sequences/ { getline; while(!$1) getline; print }' < data
Query= g1.t1 (1079 letters)
BJgh3579 186 3e-44
$


Last edited by Corona688; 12-09-2011 at 11:38 AM..
# 7  
Old 12-09-2011
Quote:
Originally Posted by Corona688
You can't tell grep to print a line by matching the line above it. grep has no memory.
Well, some versions do - there are context line control options for printing the lines before or after a matching line.

I don't think you can combine them as the OP would need though (e.g. 'just the matching line for this match, but 2 lines of after context for this one'), so it's probably not useful in this case.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenation script

Hi, I have the following reports that get generated every 1 hour and this is my requirement: 1. 5 reports get generated every hour with the names "Report.Dddmmyy.Thhmiss.CTLR" "Report.Dddmmyy.Thhmiss.ACCD" "Report.Dddmmyy.Thhmiss.BCCD" "Report.Dddmmyy.Thhmiss.CCCD"... (1 Reply)
Discussion started by: Jesshelle David
1 Replies

2. Shell Programming and Scripting

Help with String concatenation

I have a script which is migrated from AIX to Linux & now while running it is no able to concatenate string values The string concatenation step under while loop is not displaying desired result Please find below the piece of code: while read EXT_FILE ; do EXT_FILE=$EXT_FILE.ext.sent echo... (7 Replies)
Discussion started by: PreetArul
7 Replies

3. Shell Programming and Scripting

Line concatenation help

please help me on this.... cat /xx.txt 2:1 2 2:2 24 8:0 0 9:0 0 Expected result would be 2:1 2 2:2 24 8:0 0 9:0 0 (4 Replies)
Discussion started by: Aditya.Gurgaon
4 Replies

4. Shell Programming and Scripting

Concatenation of two patterns

Read the lines from the file and concatenate the lines into single line then search the string "INPUT=" from the another file and if "INPUT" is present in that file assign the concatenate patterns into "INPUT=" pattern. example: file1.txt <some lines> INPUT = <some lines> file2.txt... (3 Replies)
Discussion started by: krsureshmca
3 Replies

5. Shell Programming and Scripting

String concatenation

Hi, I have two files. cat file.txt a b c d cat file1.txt j k l m I need the output as a:j (12 Replies)
Discussion started by: nareshkumar522
12 Replies

6. UNIX for Dummies Questions & Answers

Recursive Concatenation

Hi, I have a problem with concatenation text files. I have a directory, say 'foo' Inside this folder, I have many sub folders, say 'oof1, oof2 .... oof20' Each oof directory has a number of text files inside it. I need to concatenate all the text files in oof directories within foo...... (1 Reply)
Discussion started by: Kerensa@unsw.ed
1 Replies

7. Shell Programming and Scripting

Concatenation

How can I do this: date = 4 -----------> 04 Month= 3-----------> 03 I wish to make a varibale named Var1 which will hold the value of current date and month value as: 2 digits for date. 2 digits for month. So finally var1 should hold value as 0403 --- MMDD (11 Replies)
Discussion started by: Asteroid
11 Replies

8. UNIX for Dummies Questions & Answers

File Concatenation

Hi, I want to write a generic shell script, which can concatenate n number of files passed as parameter ;to an output file which is again a parameter Example catfl.sh outfl.txt a.txt b.txt c.txt (3 files to be concatenated into a file outfl.txt) catfl.sh outfl.txt a.txt b.txt(2 files to be... (3 Replies)
Discussion started by: samit_9999
3 Replies

9. UNIX for Dummies Questions & Answers

string concatenation

my input file contains thousands of lines like below 234A dept of education 9788 dept of commerce 8677 dept of engineering How do i add a delimeter ':' after FIRST 4 CHARACTERS in a line 234A:dept of education 9788:dept of commerce 8677:dept of engineering (7 Replies)
Discussion started by: systemsb
7 Replies

10. Shell Programming and Scripting

Concatenation

What is syntax for String concatenation? I have $1 as directory. $var is some variable value '/' String value. How do I have to concatenate if I have to run utility - util $1 followed by '/' followed by $var There is no space between these three. (2 Replies)
Discussion started by: videsh77
2 Replies
Login or Register to Ask a Question