Connecting Tech Pros Worldwide Help | Site Map

Input Redirection

kaarthikeyapreyan's Avatar
Member
 
Join Date: Apr 2007
Location: India
Posts: 101
#1: 4 Weeks Ago
I have a small problem with the input redirection.

to search for a particular pattern in all files i have used this command

Expand|Select|Wrap|Line Numbers
  1. find $dir -type f -print | xargs grep -E -n -w <pattern> | tee my res.txt
this would give me the output in the format

filename : line number : matching line

I would like to have something like this in my output file

filename : line number : matching line : match

the solution that i wondering was that i would redirect my output to another command

Expand|Select|Wrap|Line Numbers
  1. grep -o <pattern>
so my new structure would look like

Expand|Select|Wrap|Line Numbers
  1. find $dir -type f -print | xargs grep -E -n -w <pattern> | tee -a my res.txt | grep -o pattern | tee -a myres.txt
my the output from tee has to be redirected in a correct way which would make this code to work fine.
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,565
#2: 3 Weeks Ago

re: Input Redirection


Ok, I will be the first to ask it.... is there a question in all of that that you would like to know the answer to?
kaarthikeyapreyan's Avatar
Member
 
Join Date: Apr 2007
Location: India
Posts: 101
#3: 3 Weeks Ago

re: Input Redirection


Yes there is ...

Quote:
I would like to have something like this in my output file

filename : line number : matching line : match
the redirection is not proper to get the desired output
so what would be the best wat to use the redirection to get my desired output

Quote:
so my new structure would look like
Expand|Select|Wrap|Line Numbers
  1. find $dir -type f -print | xargs grep -E -n -w <pattern> | tee -a my res.txt | grep -o pattern | tee -a myres.txt 
Reply