LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 244Reputation: 244Reputation: 244

if you have Python
Code:
file1=open("file1.txt").read().split(">")
file2=open("file2.txt").read().split(">")
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]
usage:
Code:
$ python myscript.py
 
Old 09-09-2010, 09:55 AM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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

Code:
#!/bin/bash

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

read -r line <&4
echo "$line"
keep="${line#>}"

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

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

        echo "$line2"

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

            echo "$line2"
        done<&5

        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
        keep="${line#>}"
    fi

    echo "$line"
done<&4

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

Rep: Reputation: 48
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.
 
  


Reply


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


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

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