How to do a simple awk search?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to do a simple awk search?
# 1  
Old 09-23-2011
How to do a simple awk search?

Hello


I am trying to do global search on access log files for a date and for either 'Error|error' string



ls -lrt *access* | grep "Sep 23" | awk '{print $9}'|xargs awk '/23\/Sep\/2011/ && /Error/ || /error'


Above matches All lines with 'error' as well unfortunately.


Is there a way to match a date and (Error or error) ??


Thank you for any ideas !!
# 2  
Old 09-23-2011
How about:


Code:
ls -lrt *access* | grep "Sep 23" | awk '{print $9}'|xargs awk '/23\/Sep\/2011/ && /[eE]rror/'

You get a noddy badge if you use "find" (one command) to eliminate the use of ls and grep and awk (three commands).

Last edited by hartz; 09-23-2011 at 09:29 AM.. Reason: Actually it is 3 commands!
# 3  
Old 09-23-2011
Like this?
Code:
awk '/Sep 23|[Ee]rror/{print $9}' *access*

--ahamed
# 4  
Old 09-23-2011
Code:
ls -lrt *access*|grep "Sep 23"|grep -E 'error|Error'

Code:
ls -lrt *access*|grep "Sep 23"|sed -n '/error\|Error/p'

Code:
ls -lrt *access*|grep "Sep 23"|awk '$0 ~ /error/ || /Error/'

# 5  
Old 09-23-2011
Or better than my last:

Code:
ls -lrt *access* | grep "Sep 23" | awk '{print $9}'|xargs awk '/23\/Sep\/2011.*[eE]rror/'

---------- Post updated at 07:35 AM ---------- Previous update was at 07:31 AM ----------

Quote:
Originally Posted by ygemici
Code:
ls -lrt *access*|grep "Sep 23"|grep -E 'error|Error'

Code:
ls -lrt *access*|grep "Sep 23"|sed -n '/error\|Error/p'

Code:
ls -lrt *access*|grep "Sep 23"|awk '$0 ~ /error/ || /Error/'

These examples assume that a file last accessed on 23 Sep will only contain errors from that date.

---------- Post updated at 07:36 AM ---------- Previous update was at 07:35 AM ----------

Quote:
Originally Posted by ahamed101
Like this?
Code:
awk '/Sep 23|[Ee]rror/{print $9}' *access*

--ahamed
This does not match the date format in the file that the op indicated. Also it searches all *access* files, which clearly the op was trying to avoid.
# 6  
Old 09-23-2011
Quote:
Originally Posted by hartz
---------- Post updated at 07:35 AM ---------- Previous update was at 07:31 AM ----------
These examples assume that a file last accessed on 23 Sep will only contain errors from that date.
These examples assume that a file last modified on 23 Sep and file name contains "error" or "Error" string.
# 7  
Old 09-23-2011
Thank you all !!

All your suggestions work !!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Having trouble with simple grep search

I have a text file (allWords.txt), that I would like to search through. Here is a snippet of what it looks like... a aah aahed aahing aahs aardvark aardvarks aardwolf ab abaci aback abacus abacuses abaft ...... I would like to use the grep search to search, line by line, for... (8 Replies)
Discussion started by: blackvelvet
8 Replies

2. Shell Programming and Scripting

Simple awk help

Hey all, so I'm using AWK in a project at work, to generate xml from csv. So far things are going relatively smoothly, but I have one thing I can't figure out. For every field in each row, I must generate <entry name=KWNamex>Field</entry> Then I will need to pull data from a second file... (6 Replies)
Discussion started by: Parrakarry
6 Replies

3. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

4. Shell Programming and Scripting

Simple awk search problem

Hello; we have : awk '/reg_exp/,0/ prints every line after the first occurrence of "reg_exp" But if I want to print rest of the lines AFTER the last occurrence of "reg_exp", how would I do it ?? Tried : awk ' ! (/reg_exp/,0)' But it errored... Thank you for any... (5 Replies)
Discussion started by: delphys
5 Replies

5. Shell Programming and Scripting

Simple (not for me) string search script

hi there, I am a complete newb to bash but am going to try and make a script to help me seach text files for strings of interest, any help that one of you gurus could pass on will be greatly received!! I want to write something like: in "text1.txt" find "string1" and copy out the line... (7 Replies)
Discussion started by: jumbo999
7 Replies

6. UNIX for Dummies Questions & Answers

Simple search pattern help

Hi I need to define a pattern that will match an open square bracket, a series of numbers fro 1 to 4 digits in length and a close square bracket. Examples of the numbers I will need to find are: or or or I am using BBEdit to search, and BBEdit uses the standard GREP search... (1 Reply)
Discussion started by: alisamii
1 Replies

7. UNIX for Dummies Questions & Answers

Too simple to search for

Hey. I'm just getting started with scripting and although i will admit i haven't searched the forum yet, i think it would be a waste of time. It really will be very simple. I want to enter a list of arguments after my script with the last being the filename. (not the first, as this is part of... (3 Replies)
Discussion started by: spudtheimpaler
3 Replies

8. Shell Programming and Scripting

Simple Search and Replace - Revisited

I have a ascii file with lines like this: 240|^M\ ^M\^M\ Old Port Marketing order recd $62,664.- to ship 6/22/99^M\ when this record gets loaded into my database, the \ is stored literally and so the user sees carriage return \ (hex 0D 5C) when what i need is carriage return line feed (hex 0D... (1 Reply)
Discussion started by: Brandt
1 Replies

9. UNIX for Dummies Questions & Answers

Simple? Search replace

in vi, if i type ctrl-J, i can shift the next line up to the current line. I need to do this whenever a specific string exists (in particular ^M) ,however i have not been able to find a way to do this in vi, sed, or awk seems simple enough. can someone help me? thanks in advance (9 Replies)
Discussion started by: Brandt
9 Replies
Login or Register to Ask a Question