The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to grep / zgrep to output ONLY the matching filename and line number? vvaidyan UNIX for Dummies Questions & Answers 3 03-12-2008 05:33 PM
filename to string cprognew High Level Programming 1 07-22-2007 05:08 PM
how can i add/modify filename after output? happyv Shell Programming and Scripting 3 10-03-2006 05:25 AM
Appending to filename a string of text grep finds HLee1981 Shell Programming and Scripting 3 09-06-2005 02:44 PM
Losing filename in grep output netguy Shell Programming and Scripting 6 04-27-2004 11:39 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-19-2007
happyv happyv is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 209
grep string and output filename

Hello,

I have over 200 files and some of them have the string like "John price $200". I would like to grep the string. Then output the filename which found the string.

I have the following script, but it ONLY output the string
echo Please input list file name:
read listn
for file in `cat $listn.txt`
do
cat $file |grep "John price $200"
done

expect output:
filename: XXXXXX
found string: John price $200


thx,
happyv
  #2 (permalink)  
Old 11-20-2007
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 921
Just change the commandline to grep to be:
Code:
grep "John price $200" $file /dev/null
Can use cut or awk to pick apart the output if you have to have it formatted differently
  #3 (permalink)  
Old 11-20-2007
edcrosbys edcrosbys is offline
Read Only
  
 

Join Date: Jul 2007
Posts: 15
not sure what OS you are using, but grep -l (that's a lowercase L) will show just the filename, not the line that matches. Do a man on grep and it should tell you how to get just the name, or tell us the os and we might be able to help some more.
  #4 (permalink)  
Old 11-20-2007
happyv happyv is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 209
thx..but how can I check my OS in unix?
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0