Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-09-2010, 07:41 AM   #16
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244

if you have Python
file3=[ k for k in open("file3.txt") if k.lstrip().startswith("Query") ]
for n,item in enumerate(file1):
    print ">"+item
    print ">"+file2[n]
    print file3[n]
$ python
Old 09-09-2010, 09:55 AM   #17
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,585

Rep: Reputation: 2914Reputation: 2914Reputation: 2914Reputation: 2914Reputation: 2914Reputation: 2914Reputation: 2914Reputation: 2914Reputation: 2914Reputation: 2914Reputation: 2914
Well like others I have a start for you but it would need some tweaking. Using the 3 files you presented I believe my output looks correctish

To give you an idea of what needs work, my script finishes when file1.txt has finished being read. A downside to this is that if there are corresponding results
in file2 or file3 they will not get printed


exec 4<"file1.txt"
exec 5<"file2.txt"

read -r line <&4
echo "$line"

while read -r line
    if [[ "${line:0:1}" == ">" ]]

        [[ -n $line2 ]] || read -r line2 <&5

        echo "$line2"

        while read -r line2
            [[ "${line2:0:1}" == ">" ]] && break

            echo "$line2"

        awk -vcheck="$keep" '$0 ~ gensub(/[[:blank:]]+.*$/,"","g",check){print RS $0;f=1}END{if(!f)print "NO SIGNIFICANT RESULTS FOUND"}' RS="Query=" file3.txt

    echo "$line"

exec 4<&- 5<&-
Old 09-10-2010, 07:43 AM   #18
sumeet inani
Registered: Oct 2008
Posts: 902
Blog Entries: 26

Rep: Reputation: 49
210 ^> in file1.txt
373 ^> in file2.txt
query appears 364 times in file3.txt
if you want 'query=' then only 17 times in file3.txt

Obviously you will get at max 210 queries in your output file if you meant to get 'query' from file3.txt.

If you meant 'query=' then only 17 in output.

Last edited by sumeet inani; 09-10-2010 at 07:50 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
awk: how can I print out a message to the screen when redirecting the output to file. quanba Programming 8 07-13-2015 02:54 AM
Trouble with making a bash script to read in different files and rename output files. rystke Linux - Software 1 05-07-2009 09:00 AM
Perl: Read a html file and output it... JoeBleaux Programming 3 04-03-2009 08:54 AM
How to read print status file in embedded linux chiragshah Linux - Newbie 1 12-31-2008 01:16 AM
How to print a given line from a file on the standard output Fond_of_Opensource Linux - Newbie 1 08-24-2006 03:45 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:30 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration