UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 6th, 2003, 07:46 AM
unix_novice unix_novice is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 2 unix_novice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to unix_novice
Question editing files in a loop

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.

Reply With Quote
  #2  
Old August 6th, 2003, 10:20 AM
Jabol Jabol is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Poland
Posts: 57 Jabol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 28 m 57 sec
Reputation Power: 10
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

Reply With Quote
  #3  
Old August 6th, 2003, 10:29 AM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,317 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 5 h 42 m 28 sec
Reputation Power: 109
Send a message via ICQ to christo Send a message via Yahoo to christo
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
__________________
This is me: http://chris.uk.com

Reply With Quote
  #4  
Old August 6th, 2003, 10:31 AM
unix_novice unix_novice is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 2 unix_novice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to unix_novice
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!

Reply With Quote
  #5  
Old August 6th, 2003, 10:33 AM
Jabol Jabol is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Poland
Posts: 57 Jabol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 28 m 57 sec
Reputation Power: 10
cat *|grep error|less

Reply With Quote
  #6  
Old August 6th, 2003, 10:35 AM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,317 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 5 h 42 m 28 sec
Reputation Power: 109
Send a message via ICQ to christo Send a message via Yahoo to christo
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

Reply With Quote
  #7  
Old August 6th, 2003, 04:40 PM
zedmelon's Avatar
zedmelon zedmelon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: under a rock
Posts: 54 zedmelon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 20 m 42 sec
Reputation Power: 10
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.

Reply With Quote
  #8  
Old August 6th, 2003, 04:55 PM
zedmelon's Avatar
zedmelon zedmelon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: under a rock
Posts: 54 zedmelon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 20 m 42 sec
Reputation Power: 10
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.

Reply With Quote
  #9  
Old August 6th, 2003, 05:16 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,389 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 22 h 17 m 29 sec
Reputation Power: 4080
>> (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

Reply With Quote
  #10  
Old August 6th, 2003, 05:32 PM
zedmelon's Avatar
zedmelon zedmelon is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: under a rock
Posts: 54 zedmelon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 20 m 42 sec
Reputation Power: 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

Reply With Quote
  #11  
Old August 13th, 2003, 10:54 AM
ctsgnb ctsgnb is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 7 ctsgnb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool other ways

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

:-)

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > editing files in a loop

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap