CUT Command and grep issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting CUT Command and grep issue
# 1  
Old 04-05-2012
CUT Command and grep issue

I am trying to grep the oracle erros evry day from the logs file. My problem is :

Code:
-rw-r----- 1 tibcolm tibco 17438361 Apr 5 11:59 RetryService-RetryService.log
-rw-r----- 1 tibcolm tibco 245303 Apr 5 12:00 ResponseService-ResponseService.log
-rw-r----- 1 tibcolm tibco 2122654 Apr 5 12:00 FinalResponseService-FinalResponseService.log
-rw-r----- 1 tibcolm tibco 40263821 Apr 5 12:00 ErrorService-ErrorService.log
-rw-r----- 1 tibcolm tibco 444207 Apr 5 12:00 CSIService-CSIService.log
-rw-r----- 1 tibcolm tibco 25881288 Apr 5 12:00 GatewayService-GatewayService.log
-rw-r----- 1 tibcolm tibco 36253634 Apr 5 12:00 BusinessService-BusinessService.log
-rw-r----- 1 tibcolm tibco 1346674 Apr 5 12:00 TransactionService-TransactionService.log

if i execute this command:

Code:
ls -lrt | cut -d " " -f 8
 
5
5
5
5
5
5
5
Apr
5
5
5
Apr
5
5

i am not getting the uniform result beacuse of the spaces inbetween. I aim id to get the current date , and then serach for grep ORA- CURRENTDATE log files .


Plz help.

Last edited by methyl; 04-05-2012 at 04:09 PM.. Reason: please use code tags
# 2  
Old 04-05-2012
Hi, try awk '{print $8}' instead of cut -d " " -f 8
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 04-05-2012
Quote:
Code:
grep ORA- CURRENTDATE log files .

Please post sample ORA- error lines from your log files (we need to see the "current date" format) and sample non-error lines. If you can, please include sample lines where the day-of-month is a single digit as well as those where the day-of-month is a double digit.
Please make it clear whether all these log files are in the same directory or whether there are subdirectories (I noticed your use of ls with the -r switch).

In my recollection Oracle logs contain all sorts of uninteresting ORA lines which are not errors. These logs however look like an Oracle custom application log, so let's assume that every ORA- line is an error.

Judging from the size of these logs you are probably not starting a new one each day (or each week, or each database restart, or whatever). Logs can become unmanageable if you don't archive them frequently - depends on local rules.

Please clarify whether you are trying to search logfiles with a unix directory timestamp of today's date, or looking through every logfile for error lines which contain today's date?

Last edited by methyl; 04-05-2012 at 05:05 PM.. Reason: typos
# 4  
Old 04-05-2012
i want to learn this awk :0
# 5  
Old 04-05-2012
In principle it's relatively simple. It reads lines one by one, splits it into tokens, and runs the code you give it for each individual line. So '{ print $8 }' gets run for each individual line, printing the 8th column.

You can also tell it to run a code block only when a condition happens, like:

Code:
#Whenever the first column is ASDF, print the 8th column
awk '$1 == "ASDF" { print $8 }' filename

# Whenever the regex /ASDF/ matches the entire line, print the 8th column
awk '/ASDF/ { print $8 }'

You can also use variables, and even arrays, and especially, associative arrays -- arrays which can use strings as indexes. A["slartibartfast"]=32; print A["slartibartfast"] would print 32 for instance.

You can have more than one code block which runs under different conditions. You could use this to find only unique values in a column:
Code:
# For each line, set A["first column"]=1.
# Once all processing is done, print every array index.
awk '{ A[$1]=1 } END { for(X in A) print X }' file

And it's configurable, too. Usually, spaces and newlines are used to separate columns and lines, but it can use whatever you want instead! Lots of possibilities from a few simple rules.

P.S: $ is an operator, not a variable. $1 is column 1. You can also use it on a variable: N=5; print $N that would use the value of N to select column 5.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with CUT command

Hi All, I am facing an issue while cutting fields with comma delimiter. There are many records with Double quotes in between. My data: aaa,bbb,"ccc, ddd",eee,fff,"ggg ,hhh",iii When i use cut command with comma delimiter, i am getting wrong data like field1=aaa field2=bbb field3="ccc... (3 Replies)
Discussion started by: krishna_gnv
3 Replies

2. Shell Programming and Scripting

Issue executing grep command on Solaris

more jdbc.xml <name>Fast_ds/DataSource</name> <property> <name>user</name> <value>COL_USER</value> </property>Command 1: grep -A1 '<name>user</name>' jdbc.xml|grep -v '<name>user</name>'|sed 's/\(<value>\|<\/value>\)//g'| sed -e 's/^*//'Output: Command 2: grep... (5 Replies)
Discussion started by: mohtashims
5 Replies

3. Shell Programming and Scripting

Issue using empty variable in grep command

Hi, I'm writing a shell script and trying to grep a variable value, it works fine as long as there is a value in /tmp/list.out which is captured in $DSK but sometimes the file tends to be empty and that is where I'm having an issue while using grep which returns nothing. I know I can use something... (15 Replies)
Discussion started by: mbak
15 Replies

4. Shell Programming and Scripting

Cut command issue

Need help to append a pipe at end of the line immediately after the cut command, I have an Input flat file with 16 feilds and I am removing the 16th feild by using the cut command as shown, Input: 354|||||CORPORTATION||||NENE PARADE|||WISBECH|CAMBRIDGESHIRE|PE13 3BY|100001| I... (5 Replies)
Discussion started by: Aditya_001
5 Replies

5. Shell Programming and Scripting

Cut command issue with shell script

I am writing a shell script to skip couple of feilds in a flat file and as a part of this I have written the below piece of code in it. cut -d '|' -f 1-17,19-31 $1 > filename To add pipe at end of the line I used below command, but it adds even to header and footer as well which i... (11 Replies)
Discussion started by: Aditya_001
11 Replies

6. UNIX for Dummies Questions & Answers

Grep command issue

How am I supposed to print with one Unix command the names (and only the names) of company JMT? Problems with scandinavian letters? By typing grep JMT url | egrep --only-matching ']+'I still have company name and + marks I should get rid of. I'd be very grateful of your help bacause I am new... (1 Reply)
Discussion started by: jht
1 Replies

7. HP-UX

Performance issue with 'grep' command for huge file size

I have 2 files; one file (say, details.txt) contains the details of employees and another file (say, emp.txt) has some selected employee names. I am extracting employee details from details.txt by using emp.txt and the corresponding code is: while read line do emp_name=`echo $line` grep -e... (7 Replies)
Discussion started by: arb_1984
7 Replies

8. Shell Programming and Scripting

issue with grep command

i am using 'psu' to grep the status of a process like below :- psu|grep -i agentf 29559 29552 0 00:53:05 ? 0:57 gn1avm_agent -n AGENTF1 28946 1 0 00:51:31 ? 0:31 gnavm_ewd -b gn1avm_agent -n AGENTF1 -c -n AGENTF1 29552 28946 0 00:53:05 ? 0:00 /bin/ksh... (6 Replies)
Discussion started by: deepakiniimt
6 Replies

9. Shell Programming and Scripting

cut command issue from a line of text

Hi, I got a line of text which has spaces in between and it is a long stream of characters. I want to extract the text from certain position. Below is the line and I want to take out 3 characters from 86 to 88 character position. In this line space is also a character. However when using cut... (5 Replies)
Discussion started by: asutoshch
5 Replies

10. Slackware

How should I cut this line using cut and grep?

not sure how to do it. wan't to delete it using cut and grep ince i would use it in the shell. but how must the command be? grep "64.233.181.103 wwwGoogle.com" /etc/hosts | cut -d the delimeter is just a space. can you help meplease. :D (1 Reply)
Discussion started by: garfish
1 Replies
Login or Register to Ask a Question