Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
print file name
Name: cesar_NZ Date: October 5, 2008 at 20:04:56 Pacific OS: solaris CPU/Ram: na Product: na
Comment:
hi All, have a script which searches log files looking for some text. can someone tell me how to print the file name only if the text is in that particular file ?? currently my script prints out all the file names it goes through :
#!/bin/ksh find ./ -name "SystemOut*.log"|while read LINE; do grep "$1 : OES \[LOGIN\]" $LINE; echo "$LINE"; done
Name: nails Date: October 6, 2008 at 18:31:29 Pacific
Reply:
Why don't you use the grep -l option?
0
Response Number 2
Name: cesar_NZ Date: October 6, 2008 at 19:39:21 Pacific
Reply:
because it doesnt work :)
0
Response Number 3
Name: Vasanth Date: October 7, 2008 at 08:38:51 Pacific
Reply:
You can use echo $? after and if its success print the values .
Vasanth
0
Response Number 4
Name: cesar_NZ Date: October 7, 2008 at 15:36:39 Pacific
Reply:
hi Vasanth, sorry didnt understand your reply. did you mean to say check if the grep command was successful then print the line ?
i.e
if [ "$?" -ne "0" ]; then echo $LINE; fi
if so, this wont work as the grep command will be successful, it just wont find any results and print out the file name which is what i am trying to avoid.
thanks.
0
Response Number 5
Name: cesar_NZ Date: October 7, 2008 at 15:38:14 Pacific
Reply:
ooops meant to say :
if [ "$?" -eq "0" ]; then
0
Response Number 6
Name: Vasanth Date: October 12, 2008 at 01:31:15 Pacific
Reply:
I just tried simple command in my box to check the return status and its perfectly worked
$ cat a.txt I am able to grep
$ grep am a.txt I am able to grep $ echo $? 0
$ grep ap a.txt $ echo $? 1
In ur case it will successful means it always return some values ?
Summary: Dear All, I have a file generating mechanism whenever the file's limit (threashold) exceeded. File name has a USER names and time stamp. Eg. John_FILE_030214_1152.001 Smith_FILE_030214_1202.001 Samant...
Summary: I hope this is the right place to post this sort of question. I've been working on a simple csh assignment but I've hit a snag which is really strange to me. It's meant to be a simple matching program...
Summary: Hi I try to add file name in end of the line of every row.Its work one file. but same code is not work other same type of file File Data: A,VF-NLD,POI for VF NLD calls,VFNLD,TAN A,VF-LOC,POI for ...