Register
It is currently Mon Sep 01, 2014 12:36 pm

help needed with tee


All times are UTC - 6 hours


Post new topic Reply to topic  [ 9 posts ] 
Author Message
 PostPosted: Tue Mar 23, 2010 6:37 am   

Joined: Tue Mar 23, 2010 6:09 am
Posts: 5
Hi,

I have the following script, which cats files from a list and then do a grep search:

cat $entry | (tee >/dev/null >(strings | egrep -i -f keywords.txt >> hits.txt) >(strings -el | egrep -i -f keywords.txt >> hits.txt)

All the hist are stored in the file hits.txt. What I want is that the variable $entry, also is stored before or after every keyword in hits.txt

So hits.txt should contain

($entry) (hit found by grep)

or

(hit found by grep) ($entry)

Is this possible?

regards


Last edited by computer4n6 on Tue Mar 23, 2010 7:55 am, edited 1 time in total.

Top
 Profile  
 PostPosted: Tue Mar 23, 2010 7:19 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
I might not get the whole thing...
as a beginning:
Code:
entry=( file1 file2 )
pattern=your_need
for i in "${entry[@]}"
do while read line
   do echo "$i $line"
   done < <(strings $i | grep -i $pattern)
done

--
HTH


Top
 Profile  
 PostPosted: Tue Mar 23, 2010 7:52 am   

Joined: Tue Mar 23, 2010 6:09 am
Posts: 5
Hi

Ok I forgot to mention that I only want the variable $entry in the file hits.txt if there is a positive result in grep

for entry in filelist; do
cat $entry | (tee >/dev/null >(strings | egrep -i -f keywords.txt >> hits.txt) >(strings -el | egrep -i -f keywords.txt >> hits.txt)
done

(my search patterns are in keywords.txt and I search first in asci and then in unicode.)

when I do

cat $entry | (tee >/dev/null >(strings | egrep -i -f keywords.txt >> $entry.txt) >(strings -el | egrep -i -f keywords >> $entry.txt)

The variable entry is saved as a filename and the keyword hit is in this file, but then I get for every hit a file and I want just one hits.txt file with the keyword and the entry
So when grep finds a hit it should write the hit and the varaible $entry to the file hits.txt

I use the tee command so that I can sent the cat result to both grep ascii and grep unicode.

regards


Last edited by computer4n6 on Tue Mar 23, 2010 8:43 am, edited 1 time in total.

Top
 Profile  
 PostPosted: Tue Mar 23, 2010 8:04 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
man grep says
Quote:
-m NUM, --max-count=NUM Stop reading a file after NUM matching lines.


Top
 Profile  
 PostPosted: Tue Mar 23, 2010 8:31 am   

Joined: Tue Mar 23, 2010 6:09 am
Posts: 5
huh?

can't follow you? I want grep to keep on searching, but I want all the hits in one file.

cat $entry | (tee >/dev/null >(strings | egrep -i -f /media/nfs_share/keywords >> /media/nfs_share/$cli_ip/hits.txt)

so far this code finds every keyword (from file) in $entry and writes the result to hits.txt
But for each grep result I also want to write the $entry to hits.txt.

So I need something that I can merge the output of grep (the keyword) with the variable $entry and store this in hits.txt


Last edited by computer4n6 on Tue Mar 23, 2010 8:41 am, edited 1 time in total.

Top
 Profile  
 PostPosted: Tue Mar 23, 2010 8:38 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
I mislead myself, because of
Quote:
So when grep found a hit it should write the hit and the varaible $entry ti hits.txt
sorry :(

it's not yet common to me to 'pass more than one input with pipe ("|")'

Code:
cat $entry | (tee >/dev/null >(strings | egrep -i -f /media/nfs_share/keywords)) >/media/nfs_share/$cli_ip/hits.txt
?


Last edited by Watael on Tue Mar 23, 2010 9:24 am, edited 3 times in total.

Top
 Profile  
 PostPosted: Tue Mar 23, 2010 8:43 am   

Joined: Tue Mar 23, 2010 6:09 am
Posts: 5
Sorry for my typo

I changed it right away ;-)


Top
 Profile  
 PostPosted: Tue Mar 23, 2010 8:47 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
so did I


Top
 Profile  
 PostPosted: Tue Mar 23, 2010 9:14 am   

Joined: Tue Mar 23, 2010 6:09 am
Posts: 5
What I do is cat a file and and then with tee I sent it to dev/null AND strings -td AND strings. This is just a short way in stead if cat the file 2 times like

cat $entry | strings | egrep -f keywords.txt >> hist.txt
cat $entry | strings -el | egrep -f keywords.txt >> hist.txt


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP