|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
I am a unix novice, so please forgive me if this sounds silly.
I have to go through about 350 log files on a Unix system, all in the same directory. I decided to write a small script to go through all of the files in that directory and invoke the "vi" command on them. I did something like this: find . -type f -print | while read f; do { vi $f } done That kinda worked, it does invoke vi on the first file. However, it seems to continue, putting all kinds of commands on the vi command line, and it eventually throws me out of vi on the first file. I need to find a way to get the "vi" command to wait until I can look through the file and quit out of vi before it goes to the next file. Can anyone help? thanks. |
|
#2
|
|||
|
|||
|
if you are only reading them (if they'er logs i don't suppose you're doing sth with them) there's some better solution of your problem:
cat *|less |
|
#3
|
||||
|
||||
|
if all you want to do is read them, then less * would do the job fine, but if you want to parse data out of them, then you'll need to script something with sed, grep and awk, or probably more sensibly just write a PERL script. What exactly are you hoping to do with them? just reading log files is an odd thing to do.
christo
__________________
. Spiration channels: Free scripts, programming tutorials and articles Dotcut alerts: Online Press cuttings / news alerts Clearprop: UK microlight school, wiltshire Uk dating: UK safe dating with Topdates About Christo . . |
|
#4
|
|||
|
|||
|
Less may work, then...all i have to do is go through and look for any errors, warnings, check row counts, things like that.
Thanks! |
|
#5
|
|||
|
|||
|
cat *|grep error|less
|
|
#6
|
||||
|
||||
|
if you can give a detailed example of the data you need, then we can help you to knock up a proper script for the job.. otherwise you'll have to settle with Jabol's cat *|grep error|less. I think he's probably just trying to give you hints tho.
christo |
|
#7
|
||||
|
||||
|
one more idea
I don't know how big these 350 files are, but even at one line each, your screen will fill several times over. If these are just subsequent versions of the same logfile, then you'll probably not need to know which file contains what error.
example: http.access.20030806-04.log http.access.20030806-05.log http.access.20030806-06.log etc... However, if these logs come from many different sources, like database.access.20030806.log http.access.Aug2003.log sudo.3rdquarter.log ...then that many lines will be confusing when you see an error. If you use grep first, then it'll show you which file contains the found line. grep error ./* example: [15:24:24 zedmelon@kilby bin] grep CMD ./* ./pidmail:CMD=${0##*/} ./pidmailer: echo "$CMD: ./startApache:CMD=${0##*/} ./startApache:EXECMD="/opt/apache/current/bin/httpsdctl.cp startssl" ./startApache: echo "Run $CMD as root, please. ./startApache: echo "$CMD: argument required." ./startApache: $CMD 1 | 2 | 3 | 4 | staging | test | all | h ./startApache: time, $CMD does no redundancy check." ./startApache:ssh $1 $EXECMD ./startApache: for COMPARE in $ACCPTCMD ./startApache: echo "$CMD: illegal option: $CHECKIT" Of course this assumes that the word "error" appears verbatim in each file. If you have a file that contains "Error", a file that contains "ERR", and a file that contains "ERROR," you can use the -i flag, telling grep to ignore case. -zedmelon
__________________
Mother says my .sig can beat up your .sig. |
|
#8
|
||||
|
||||
|
ERG
unix_novice, I must have missed your post before about looking for warnings and row counts (is a row count the number of LINES in the file, or info STORED in the file?).
maybe something like: Code:
FILELIST=`ls -1`
ERRLIST='error ERROR Warning! ABORT'
for CHECK in $FILELIST
do
wc -l $CHECK
for ERR in $ERRLIST
do
grep $ERR $CHECK
done
echo
done
(Thanks to Scorpions4ever: my tabs no longer get nuked) I don't know; that seems horribly inefficient, but I'm brainlocked for anything better, unless there are ways to tell the logs from different applications from other logs, just by filename. Then at the expense of getting more complex, your script can spend less time searching ALL files for EVERY possible error, even errors that will only be encountered in other files. good luck. -zedmelon Last edited by zedmelon : August 6th, 2003 at 05:41 PM. |
|
#9
|
||||
|
||||
|
>> (wish I knew how to format this better, but my tabs get nuked)
Post your code within [ code] and [ /code] tabs (remove the leading space within the square brackets).
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#10
|
||||
|
||||
|
okay, I'm leaving
Thanks.
I'm leaving now, so you won't get to teach me THREE things in one day. ;) Have a good one. -zedmelon |
|
#11
|
|||
|
|||
|
if all the file to be scanned are in the same directory :
grep -E 'error|ERROR|Warning!|ABORT' * or ls | xargs -i grep -E 'error|ERROR|Warning!|ABORT' {} or ls -l | awk '{print$9}' | xargs -i grep -E 'error|ERROR|Warning!|ABORT' {} or just with a loop as suggested by zedmelon :-) |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > editing files in a loop |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|