log file question [closed]
I have a program that put out a log file to the /var/log/myfiles/
directory.
these files are kept small in size and the file name is incremented by number . at the end of the day I want to cat the last file to a report.
I'm drawing a blank on doing this. I can find the file but its not working in a script.
/var/log/myfile/master
/var/log/myfile/master.1
/var/log/myfile/master.2
/var/log/myfile/master.3
syslog
closed as unclear what you're asking by Rui F Ribeiro, roaima, Jeff Schaller, Archemar, msp9011 Jan 21 at 13:41
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I have a program that put out a log file to the /var/log/myfiles/
directory.
these files are kept small in size and the file name is incremented by number . at the end of the day I want to cat the last file to a report.
I'm drawing a blank on doing this. I can find the file but its not working in a script.
/var/log/myfile/master
/var/log/myfile/master.1
/var/log/myfile/master.2
/var/log/myfile/master.3
syslog
closed as unclear what you're asking by Rui F Ribeiro, roaima, Jeff Schaller, Archemar, msp9011 Jan 21 at 13:41
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
in your example, should we assume that the.3
version is the "last"?
– Jeff Schaller
Jan 20 at 22:07
Are you really using syslog to write these files? Andlogrotate
to cycle them? If so, thenmaster
would be more recent thanmaster.3
, and somaster
should be the "last" file. Is that correct?
– roaima
Jan 20 at 22:37
add a comment |
I have a program that put out a log file to the /var/log/myfiles/
directory.
these files are kept small in size and the file name is incremented by number . at the end of the day I want to cat the last file to a report.
I'm drawing a blank on doing this. I can find the file but its not working in a script.
/var/log/myfile/master
/var/log/myfile/master.1
/var/log/myfile/master.2
/var/log/myfile/master.3
syslog
I have a program that put out a log file to the /var/log/myfiles/
directory.
these files are kept small in size and the file name is incremented by number . at the end of the day I want to cat the last file to a report.
I'm drawing a blank on doing this. I can find the file but its not working in a script.
/var/log/myfile/master
/var/log/myfile/master.1
/var/log/myfile/master.2
/var/log/myfile/master.3
syslog
syslog
edited Jan 20 at 22:35
roaima
43.9k555118
43.9k555118
asked Jan 20 at 21:55
ml41782ml41782
1
1
closed as unclear what you're asking by Rui F Ribeiro, roaima, Jeff Schaller, Archemar, msp9011 Jan 21 at 13:41
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Rui F Ribeiro, roaima, Jeff Schaller, Archemar, msp9011 Jan 21 at 13:41
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
in your example, should we assume that the.3
version is the "last"?
– Jeff Schaller
Jan 20 at 22:07
Are you really using syslog to write these files? Andlogrotate
to cycle them? If so, thenmaster
would be more recent thanmaster.3
, and somaster
should be the "last" file. Is that correct?
– roaima
Jan 20 at 22:37
add a comment |
in your example, should we assume that the.3
version is the "last"?
– Jeff Schaller
Jan 20 at 22:07
Are you really using syslog to write these files? Andlogrotate
to cycle them? If so, thenmaster
would be more recent thanmaster.3
, and somaster
should be the "last" file. Is that correct?
– roaima
Jan 20 at 22:37
in your example, should we assume that the
.3
version is the "last"?– Jeff Schaller
Jan 20 at 22:07
in your example, should we assume that the
.3
version is the "last"?– Jeff Schaller
Jan 20 at 22:07
Are you really using syslog to write these files? And
logrotate
to cycle them? If so, then master
would be more recent than master.3
, and so master
should be the "last" file. Is that correct?– roaima
Jan 20 at 22:37
Are you really using syslog to write these files? And
logrotate
to cycle them? If so, then master
would be more recent than master.3
, and so master
should be the "last" file. Is that correct?– roaima
Jan 20 at 22:37
add a comment |
2 Answers
2
active
oldest
votes
On the assumption that the file you want ("last file") is the one with the highest numeric extension, you could use zsh's powerful globbing capabilities:
zsh -c 'cat /var/log/master.*(oe['REPLY=${REPLY##*.}']n[-1]) > report'
The wildcard/glob expansion is:
/var/log/master.*
-- match files that start with/var/log/master.
( ... )
-- defines the "glob qualifier"
o
-- order the results
e['REPLY=${REPLY##*.}']
-- the results to sort are given by stripping the leading text through the first period, turning, for example,/var/log/myfile/master.3
into just3
n
-- order the results numerically, not alphabetically
[-1]
-- after sorting the results, pull out only the last element (largest element)
add a comment |
Problem solved. I changed the file names to include date and time stamp. Easier to identify and extract the needed data.
Master-20-Jan-2019-18:20.log
Master-20-Jan-2019-18:45.log
Master-20-Jan-2019-19:18.log
M
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
On the assumption that the file you want ("last file") is the one with the highest numeric extension, you could use zsh's powerful globbing capabilities:
zsh -c 'cat /var/log/master.*(oe['REPLY=${REPLY##*.}']n[-1]) > report'
The wildcard/glob expansion is:
/var/log/master.*
-- match files that start with/var/log/master.
( ... )
-- defines the "glob qualifier"
o
-- order the results
e['REPLY=${REPLY##*.}']
-- the results to sort are given by stripping the leading text through the first period, turning, for example,/var/log/myfile/master.3
into just3
n
-- order the results numerically, not alphabetically
[-1]
-- after sorting the results, pull out only the last element (largest element)
add a comment |
On the assumption that the file you want ("last file") is the one with the highest numeric extension, you could use zsh's powerful globbing capabilities:
zsh -c 'cat /var/log/master.*(oe['REPLY=${REPLY##*.}']n[-1]) > report'
The wildcard/glob expansion is:
/var/log/master.*
-- match files that start with/var/log/master.
( ... )
-- defines the "glob qualifier"
o
-- order the results
e['REPLY=${REPLY##*.}']
-- the results to sort are given by stripping the leading text through the first period, turning, for example,/var/log/myfile/master.3
into just3
n
-- order the results numerically, not alphabetically
[-1]
-- after sorting the results, pull out only the last element (largest element)
add a comment |
On the assumption that the file you want ("last file") is the one with the highest numeric extension, you could use zsh's powerful globbing capabilities:
zsh -c 'cat /var/log/master.*(oe['REPLY=${REPLY##*.}']n[-1]) > report'
The wildcard/glob expansion is:
/var/log/master.*
-- match files that start with/var/log/master.
( ... )
-- defines the "glob qualifier"
o
-- order the results
e['REPLY=${REPLY##*.}']
-- the results to sort are given by stripping the leading text through the first period, turning, for example,/var/log/myfile/master.3
into just3
n
-- order the results numerically, not alphabetically
[-1]
-- after sorting the results, pull out only the last element (largest element)
On the assumption that the file you want ("last file") is the one with the highest numeric extension, you could use zsh's powerful globbing capabilities:
zsh -c 'cat /var/log/master.*(oe['REPLY=${REPLY##*.}']n[-1]) > report'
The wildcard/glob expansion is:
/var/log/master.*
-- match files that start with/var/log/master.
( ... )
-- defines the "glob qualifier"
o
-- order the results
e['REPLY=${REPLY##*.}']
-- the results to sort are given by stripping the leading text through the first period, turning, for example,/var/log/myfile/master.3
into just3
n
-- order the results numerically, not alphabetically
[-1]
-- after sorting the results, pull out only the last element (largest element)
answered Jan 20 at 22:23
Jeff SchallerJeff Schaller
40.1k1054126
40.1k1054126
add a comment |
add a comment |
Problem solved. I changed the file names to include date and time stamp. Easier to identify and extract the needed data.
Master-20-Jan-2019-18:20.log
Master-20-Jan-2019-18:45.log
Master-20-Jan-2019-19:18.log
M
add a comment |
Problem solved. I changed the file names to include date and time stamp. Easier to identify and extract the needed data.
Master-20-Jan-2019-18:20.log
Master-20-Jan-2019-18:45.log
Master-20-Jan-2019-19:18.log
M
add a comment |
Problem solved. I changed the file names to include date and time stamp. Easier to identify and extract the needed data.
Master-20-Jan-2019-18:20.log
Master-20-Jan-2019-18:45.log
Master-20-Jan-2019-19:18.log
M
Problem solved. I changed the file names to include date and time stamp. Easier to identify and extract the needed data.
Master-20-Jan-2019-18:20.log
Master-20-Jan-2019-18:45.log
Master-20-Jan-2019-19:18.log
M
answered Jan 21 at 0:18
ml41782ml41782
1
1
add a comment |
add a comment |
in your example, should we assume that the
.3
version is the "last"?– Jeff Schaller
Jan 20 at 22:07
Are you really using syslog to write these files? And
logrotate
to cycle them? If so, thenmaster
would be more recent thanmaster.3
, and somaster
should be the "last" file. Is that correct?– roaima
Jan 20 at 22:37