How to grep -v and omit all results matching 'x' in column 'y'
Hello,
I'm trying to find out if such a thing is possible. Scenario: in /var/log/ I have maillog files dating back to 2006. Example: Code:
-rw-r--r-- 1 root wheel - 79248 Sep 1 2006 maillog.1939 Code:
-rw-r--r-- 1 root wheel - 322481 Sep 1 22:00 maillog.45588 Code:
ls -lt | grep maillog | grep 'Sep 1' I would like to replace "..." with a function that will omit from the output, all entries that match 2006 from the 9th column. Many thanks in advance comrades! |
Code:
grep -v ' 2006 ' |
The ones you're after don't have a year, they have a time... and the unique thing about the timestamp is, they have a colon. So try:
Code:
ls -lt | grep maillog | grep : |
Hi,
If you look at the ls man page you see this option: --time-style=STYLE. If you use long-iso for STYLE you get a cinsistent date output. Example: Code:
ls -l |
Quote:
Code:
ls -lt | awk '$0 ~ /maillog/ && $9 !~ /:/' Quote:
Code:
ls -lt | awk '$0 ~ /maillog/ && $9 !~ /2006/' |
Quote:
---------- Post added 09-12-11 at 11:27 AM ---------- Quote:
|
Quote:
The awk looks promising, but the output doesn't omit based on the year: Code:
# ls -lt | awk '$0 ~ /maillog/ && $9 !~ /:/' |
Quote:
Quote:
Code:
ls -lt | awk '$0 ~ /maillog/ && $9 ~ /:/' |
Never mind, I misread the original question.......
|
Quote:
If you wouldn't mind terribly, could you please expand on the functions of the tilde, double ampersand, and '/' functions in the awk statement? |
Quote:
http://www.gnu.org/s/gawk/manual/ http://www.grymoire.com/Unix/Awk.html Two things to take in mind: first awk parses one line at a time (record) and splits the record into fields based on the value of the field separator, FS, which is one or multiple spaces by default. Second, awk applies all the rules to each line where a rule is basically: Code:
pattern { action } Code:
awk '$0 ~ /maillog/ && $9 ~ /:/' Translated in real words the command means: if the record matches "maillog" and the 9th field matches ":" print out the record itself. Hope it is clear. |
Quote:
|
All times are GMT -5. The time now is 07:12 PM. |