Exploring the grep options


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Exploring the grep options
# 1  
Old 06-07-2012
Error Exploring the grep options

Hi Folks,
I have one query I have a log file to which I reach to putty and I open that particular log file in vi editor and search through /pattern, Suppose I have to search

HTML Code:
<ProgramId>627857272120951075</ProgramId>
Then I have to open abc.log
Code:
cd /var/log/
ls -ltr
vi abc.log
/627857272120951075

I want to know is there any other way in which without opening the log file first
we can know that particular log file conatain the
627857272120951075 this or not any other thing grep or egrep .
# 2  
Old 06-07-2012
grep

Hi,
Try this,
Code:
grep 'pattern' path/file
awk '/pattern/{t=1;print;}END{if(t!=1){print "pattern not found";}}' path/file

Cheers,
Ranga:-)
This User Gave Thanks to rangarasan For This Post:
# 3  
Old 06-07-2012
Question

Quote:
Originally Posted by rangarasan
Hi,
Try this,
Code:
grep 'pattern' path/file
awk '/pattern/{t=1;print;}END{if(t!=1){print "pattern not found";}}' path/file

Cheers,
Ranga:-)

Hi Ranga,
Thanks a lot can you also please explain what the second line of command is doing..!! Is there any one line command that will do the task, i dont want to run a script for this..!
# 4  
Old 06-07-2012
awk

In awk, we are checking the pattern if found just print the matched string else print the string 'not found'..
# 5  
Old 06-07-2012
The awk line can be far more simple:

Code:
awk '/627857272120951075/{print $0}' /var/log/abc.log

what awk is doing is checking each line 1 at a time for the string "627857272120951075", if (and only if) that string is found, print the entire line.

---------- Post updated at 04:21 PM ---------- Previous update was at 04:17 PM ----------

Also, please don't double post. You have the same exact questions under a separate thread by *ALMOST* the same exact title.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Solaris

grep options in solaris

Hi, I am interested in knowing the grep optiojs availabel in solaris box, to get the grep results in one line from the log files. only the matched values need to be displayed. I need ot find the values in a message where the search values will be in separate lines of the input. like:... (10 Replies)
Discussion started by: sudha143
10 Replies

2. UNIX for Dummies Questions & Answers

Grep Options

Hi Folks, I have one query I have a log file to which I reach to putty and I open that particular log file in vi editor and search through /pattern, Suppose I have to search <ProgramId>627857272120951075</ProgramId> Then I have to open abc.log cd /var/log/ ls -ltr vi abc.log... (1 Reply)
Discussion started by: SankalpS
1 Replies

3. UNIX for Advanced & Expert Users

Problem with grep command options in Sunsolaris

Hi Experts I need the following output from grep command of Sunsolaris on a set of input files. Output:........ 1st search string from file1 2nd search string from file1 3rd search string from file1 1st search string from file2 2nd search string from file2 3rd search string from... (3 Replies)
Discussion started by: ks_reddy
3 Replies

4. Shell Programming and Scripting

Grep options

Hi Team, I have a list of 12000 files and i am need to search for the names of the file which has long version numbers (say more than 5 decimals).. With the below instance u~15.1.4.1.2.1.5.1.5.1.24.1.24.1.5 lk-l~22.1.3.1.9.1.7.1.24.1.23 YDFVALLN.CPY~1 YEUPCASE.CPY~1 YFPRSTID.CPY~1... (2 Replies)
Discussion started by: ganga.dharan
2 Replies
Login or Register to Ask a Question