log file question [closed]












-1















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









share|improve this 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? 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


















-1















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









share|improve this 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? 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
















-1












-1








-1








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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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? 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





















  • 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



















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












2 Answers
2






active

oldest

votes


















1














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 just 3


  • n -- order the results numerically, not alphabetically


  • [-1] -- after sorting the results, pull out only the last element (largest element)






share|improve this answer































    0














    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






    share|improve this answer






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      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 just 3


      • n -- order the results numerically, not alphabetically


      • [-1] -- after sorting the results, pull out only the last element (largest element)






      share|improve this answer




























        1














        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 just 3


        • n -- order the results numerically, not alphabetically


        • [-1] -- after sorting the results, pull out only the last element (largest element)






        share|improve this answer


























          1












          1








          1







          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 just 3


          • n -- order the results numerically, not alphabetically


          • [-1] -- after sorting the results, pull out only the last element (largest element)






          share|improve this answer













          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 just 3


          • n -- order the results numerically, not alphabetically


          • [-1] -- after sorting the results, pull out only the last element (largest element)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 20 at 22:23









          Jeff SchallerJeff Schaller

          40.1k1054126




          40.1k1054126

























              0














              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






              share|improve this answer




























                0














                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






                share|improve this answer


























                  0












                  0








                  0







                  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






                  share|improve this answer













                  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







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 21 at 0:18









                  ml41782ml41782

                  1




                  1















                      Popular posts from this blog

                      How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                      is 'sed' thread safe

                      How to make a Squid Proxy server?