![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell script to search for text in a file and copy file | imeadows | UNIX for Dummies Questions & Answers | 9 | 11-12-2008 09:12 PM |
| shell script to edit the content of a file | tiger99 | Shell Programming and Scripting | 3 | 01-31-2008 04:43 AM |
| Urgent: selecting unique specific content of a file using shell script | jisha | Shell Programming and Scripting | 2 | 01-08-2008 08:45 AM |
| search for the contents in many file and print that file using shell script | cdfd123 | Shell Programming and Scripting | 3 | 10-07-2007 11:17 PM |
| Korn Shell Script - Read File & Search On Values | run_unx_novice | Shell Programming and Scripting | 2 | 06-15-2005 08:20 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
read -p "what date ?" vardate
echo $vardate awk -v d="$vardate" '$0 ~ d{print}' weblog i find this one that really works its output me the correct line and everything... but each time i need to go and change the filename in order to find what i want... |
|
||||
|
I recently responded to a similar question of yours here: Shell script to search for text in a file and copy file Code:
#!/bin/sh case $# in 0|1) echo "syntax: $0 date files ..." >&2; exit 2;; esac date=$1 shift awk -v d="$date" '$0 ~ d' "$@" This expects the date as the first parameter, and a list of files as the remaining parameters. Those are passed through to awk in "$@" after the first argument (the date) has been shifted off and passed to the awk script as a variable. I took out the { print } because that is the default action; this is probably less readable, so if you don't use awk much, it might be safer to leave it in. Of course, this simple script is exactly equivalent to grep without any options or other bells & whistles. Last edited by era; 04-20-2008 at 01:45 PM.. Reason: Fix case statement to accept more than one file, duh |
|
||||
|
thanx for replying era!!!
but i am afraid this does not work. i think that in the script that u write it checking throught files date.. what i want is to check throught files text content... i have the traffic of my website... in a directory named traffic... the traffic directory have files with each webpage ip that visit my website!! so i want the script to be able to output me the ips that visit my website the date that i ask... |
|
||||
|
You might think wrong. Try it. Like I already wrote, this is equivalent to grep date file For example, grep 2008-04-20 traffic/127.0.0.1 would search for 2008-04-20 in the file traffic/127.0.0.1. Maybe your logs use a different date format, but you get the idea. PS. Simpler still awk script, provided your date format doesn't have slashes in it: Code:
#!/bin/sh case $# in 0|1) echo "syntax: $0 date files ..." >&2; exit 2;; esac date=$1 shift awk "/$date/" "$@" Last edited by era; 04-20-2008 at 03:45 PM.. Reason: Clarifying (?) .... grep .... example .... |
|
||||
|
i try it!!! and it does not work!! its get me a syntax error.. i used it like this Code:
#!/bin/sh read -p "what date" vardate echo $vardate case $# in 0|1) echo "syntax: $0 date files ..." >&2; exit 2;; esac date=$1 shift awk "/$date/" "$@" am i wrong somewhere?? my log files text are in this format : 162.12.56.7 Tues Feb 8 21:02:35 GMT 2008 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|