LinuxQuestions.org
Visit Jeremy's Blog.
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, 06: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, 08:55 AM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
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, 06:43 AM   #18
sumeet inani
Member
 
Registered: Oct 2008
Posts: 908
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 06: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 01:54 AM
Trouble with making a bash script to read in different files and rename output files. rystke Linux - Software 1 05-07-2009 08:00 AM
Perl: Read a html file and output it... JoeBleaux Programming 3 04-03-2009 07:54 AM
How to read print status file in embedded linux chiragshah Linux - Newbie 1 12-31-2008 12:16 AM
How to print a given line from a file on the standard output Fond_of_Opensource Linux - Newbie 1 08-24-2006 02:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:33 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
Open Source Consulting | Domain Registration