Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Unhappy get a string in a file


    ---- log.txt---------
    UNISON started propagating changes at 03:00:53 on 14 Mar 2006
    [CONFLICT] Skipping ./a.tmp/anacron/cron.daily
    [BGN] Copying ./a.tmp/file100
    from /home/ela
    to //localhost.localdomain//home/ela
    [END] Copying ./a.tmp/file100
    UNISON finished propagating changes at 03:00:53 on 14 Mar 2006


    Synchronization complete (1 item transferred, 3 skipped, 0 failures)
    skipped: ./a.tmp/anacron/cron.daily
    skipped: ./a.tmp/asdasd/asdasd
    skipped. sdasdhasdasdasd
    -----------------------------------------------------

    please help.... i need to get the number "3" in the log file... this number change depending on how many files have been skipped during the file transfer...

    i tried using awk but it also get 03:00:53's since awk gets the value through columns... and also tried to tail it but i dont get accurate results since using awk include all the columns in a file even the blank line...

    i really need to get the number of skipped files...

    please please help....

  2. #2
    maybe it's not the textbook solution .. (maybe it is! :)
    Code:
    $ cat file
    Synchronization complete (1 item transferred, 3 skipped, 0 failures)
    Synchronization complete (1 item transferred, 31 skipped, 0 failures)
    $ sed -n 's/\(.*\)\ \(.*\)\ skipped\(.*\)/\2/p' file
    3
    31
    Pay attention to the \space since they have to be there to work.
    Basicly the sed translates to:
    -n [dont print anything] s[unstitute]
    the pattern we are looking for:
    \(.*\) anything followed by
    \space
    \(.*\) anything followed by
    \space
    skipped

    the \2 than prints only the 'second anything we found'
    /p to print the \2

    Another sed that also works:
    Code:
    sed -n 's/.*transferred,\ \(.*\)skipped.*/\1/p' file
    You could also consider using: cut
    Now what? You have Linux installed and running. The GUI is working fine, but you are getting tired of changing your desktop themes. You keep seeing this "terminal" thing. Don't worry, they'll show you what to do @
    <~ http://www.linuxcommand.org/ ~>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •