| Author |
tailing multiple files in to log file
|
|
| sally.bridges@gmail.com 2004-11-24, 8:12 am |
| I have over 60 seporate files that I would like to tail the last 10
lines of and ,erge in to one file.
i would like to write a shell script to do this but am having fun
knowing where to start.
i have looked at the manual for tail and can see that it can do muliple
files but will i have to name all of the seporate filenames or could i
use a dos like switch of *.txt for these files and then tail the output
to the file i want.
any help gratefully recived a windowz dos freek ! !
| |
| Pedro Graca 2004-11-24, 8:12 am |
| sally.bridges@gmail.com wrote:
> i have looked at the manual for tail and can see that it can do muliple
> files but will i have to name all of the seporate filenames or could i
> use a dos like switch of *.txt for these files and then tail the output
> to the file i want.
<unlurk reason="this one I know how to do :-)">
~$ echo "aaaaa" > X133.txt
~$ echo "aaaaa" >> X133.txt
~$ echo "aaaaa" >> X133.txt
~$ echo "aaaaa" >> X133.txt
~$
~$ echo "bbb" > X45122.txt
~$ echo "bbb" >> X45122.txt
~$ echo "bbb" >> X45122.txt
~$ echo "bbb" >> X45122.txt
~$
~$ tail -qn2 X*txt
aaaaa
aaaaa
bbb
bbb
~$
</unlurk>
--
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com/
== ** ## !! !! ## ** ==
TEXT-ONLY mail to the complete "Reply-To:" address ("My Name" <my@address> ) may
bypass the spam filter. I will answer all pertinent mails from a valid address.
| |
| Chuck Dillon 2004-11-24, 8:12 am |
| sally.bridges@gmail.com wrote:
> I have over 60 seporate files that I would like to tail the last 10
> lines of and ,erge in to one file.
>
> i would like to write a shell script to do this but am having fun
> knowing where to start.
>
> i have looked at the manual for tail and can see that it can do muliple
> files but will i have to name all of the seporate filenames or could i
> use a dos like switch of *.txt for these files and then tail the output
> to the file i want.
> any help gratefully recived a windowz dos freek ! !
>
On systems where tail can only operate on one file at a time you need
to use a shell loop or simpler yet use xargs...
find *.txt -print | xargs -n1 tail -10
or
ls *.txt | xargs -n1 tail -10
or
printf "tail -10 %s\n" *.txt | sh
The first two feed the file names one per line to xargs which runs tail
once for each line it reads.
The last one generates the tail commands and pipes them into a shell
which executes them.
-- ced
--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.
| |
| Måns Rullgård 2004-11-24, 6:28 pm |
| Chuck Dillon <spam@nimblegen.com> writes:
> find *.txt -print | xargs -n1 tail -10
> or
> ls *.txt | xargs -n1 tail -10
> or
> printf "tail -10 %s\n" *.txt | sh
>
> The first two feed the file names one per line to xargs which runs
> tail once for each line it reads.
>
> The last one generates the tail commands and pipes them into a shell
> which executes them.
While we're at it:
ls *.txt | while read file; do tail -10 "$file"; done
or
for file in *.txt; do tail -10 "$file"; done
or
find *.txt -exec tail -10 '{}' \;
--
Måns Rullgård
mru@inprovide.com
| |
| sally.bridges@gmail.com 2004-11-24, 6:28 pm |
| yep , i have one of those systems that can only operate tail one file
at a time , guess they wanted me to have a fun day
I can display the results to screen and when i try to plop this in a
file it errors i am putting >>myfile on the end .
normally works , but guess not this time. if i did a ls-l >> checkme
can we write a loop to go through the checkme file and pick up the txt
file names there, i am also guessing that this will have carrage
returns in and so may need to be detoxed.
| |
| sally.bridges@gmail.com 2004-11-24, 6:28 pm |
| very silly question but how do i enter the funny symbal before the ; at
the end
or do i copy and past in to my shell ! !
Sally
| |
| Måns Rullgård 2004-11-24, 6:28 pm |
| "sally.bridges@gmail.com" <sally.bridges@gmail.com> writes:
> very silly question but how do i enter the funny symbal before the ; at
> the end
The backslash (\) ? I can't tell you, since I don't know which
keyboard layout you are using, but since you seem to be posting from
the UK, I suggest looking for it somewhere near the enter key.
--
Måns Rullgård
mru@inprovide.com
| |
| Christopher Nehren 2004-11-24, 6:28 pm |
| On Wed, Nov 24, 2004 at 08:29:10 EST, Pedro Graca scribbled these
non-portable markings:
> <unlurk reason="this one I know how to do :-)">
> ~$ echo "aaaaa" > X133.txt
> ~$ echo "aaaaa" >> X133.txt
> ~$ echo "aaaaa" >> X133.txt
> ~$ echo "aaaaa" >> X133.txt
> ~$
> ~$ echo "bbb" > X45122.txt
> ~$ echo "bbb" >> X45122.txt
> ~$ echo "bbb" >> X45122.txt
> ~$ echo "bbb" >> X45122.txt
> ~$
> ~$ tail -qn2 X*txt
^ *BUZZ* *NOT PORTABLE*
POSIX doesn't understand a -q option to tail[1]. Perhaps you should give
warning before issuing GNU-specific advice.
1: http://tinyurl.com/4yggh
(The Open Group's Single Unix Specification, version 2, online reference
for tail(1))
--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
Linux: "How rebellious ... in a conformist sort of way."
Unix is user friendly. However, it isn't idiot friendly.
| |
| Pedro Graca 2004-11-24, 6:28 pm |
| Christopher Nehren wrote:
> On Wed, Nov 24, 2004 at 08:29:10 EST, Pedro Graca scribbled these
> non-portable markings:
> ^ *BUZZ* *NOT PORTABLE*
Oops, sorry everyone.
> POSIX doesn't understand a -q option to tail[1]. Perhaps you should give
> warning before issuing GNU-specific advice.
Thanks, I didn't know that.
My documentation ('man tail' from GNU/Linux Debian) doesn't talk about
POSIX portability. I will be more careful in the future.
> 1: http://tinyurl.com/4yggh
>
> (The Open Group's Single Unix Specification, version 2, online reference
> for tail(1))
Just got myself a new bookmark!
http://www.opengroup.org/onlinepubs/007908799/
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address> )
may bypass my spam filter. If it does, I may reply from another address!
| |
| J.L.Cooper 2004-11-26, 7:50 am |
|
"Måns Rullgård" <mru@inprovide.com> wrote in message
news:yw1xhdnfrxuj.fsf@ford.inprovide.com...
>
> The backslash (\) ? I can't tell you, since I don't know which
> keyboard layout you are using, but since you seem to be posting from
> the UK, I suggest looking for it somewhere near the enter key.
>
If it is a UK keyboard then it is on the left next to the shift key.
If it is not a UK keyboard then just look for the key with the \ symbol on
it it is kind of important so it should have one.
--------------
Jason Cooper
| |
| Chuck Dillon 2004-11-26, 7:50 am |
| sally.bridges@gmail.com wrote:
> yep , i have one of those systems that can only operate tail one file
> at a time , guess they wanted me to have a fun day
>
> I can display the results to screen and when i try to plop this in a
> file it errors i am putting >>myfile on the end .
Whenever you get an error the single most important things to post when
you need help figuring it out are: (1) the exact command you used and
(b) the exact text of any errors/messages you saw as a result.
You didn't include either so it's a bit hard to help you.
-- ced
>
> normally works , but guess not this time. if i did a ls-l >> checkme
>
> can we write a loop to go through the checkme file and pick up the txt
> file names there, i am also guessing that this will have carrage
> returns in and so may need to be detoxed.
>
--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.
|
|
|
|