3

I've pasted a log generated by rsync running through Cygwin on a Windows 2008 server. I am rsync'ing data over to a new file server (Synology), and after trimming out anything that's not an error, I have a few different errors to deal with, and they're all interlaced.

What I want is to quickly and easily, preferably with vim, separate out the different error types, so that all of the lines that start with "rsync: send_files (blah blah)" are consolidated, and all of the lines that start with "file has vanished: " are consolidated, etc.

Basically I'm trying to find a way to match a regex, yank/delete all pertinent lines, then paste them either in the same file but all in the same place, or in a new file/buffer.

EDIT: a thought just occurred to me. If I ran sort on this data, it would probably do what I wanted. I could do that with external tools, but is it possible to do this inside vim, either by calling sort within vim or better still, using tools within vim's native environment. Really I'm using this as an exercise for me in learning how to use vim better, not other tools.

A small sample of the log file, with some information redacted:

rsync: send_files failed to open "/cygdrive/E/Users/SharedFiles/3DS SALES/3DS MARKETING/PORTFOLIOS/2012 - Portfolios/Signage"XXXXXXXX Full Res photos/xxxxx xx sky/.DS_Store": Permission denied (13)
file has vanished: "/cygdrive/E/Users/SharedFiles/3DS SALES/CURRENT SALES/xxxxxxxxx xxx xxxxx xxxxx xxxx - xxxx/02_PROPOSAL-QUOTATION/15-002 - xxxx xxxx xxxx - Replacement  Private Fuction  Event Board.xlsx"
rsync: opendir "/cygdrive/E/Users/SharedFiles/3DS SALES/CURRENT SALES/Archived Projects/ARCHIVES -xxxxx light/Hootsuite xxxxxx Info" failed: Permission denied (13)
rsync: opendir "/cygdrive/E/Users/SharedFiles/3DS STAFF/Cortney/xxxxx/MANUAL/Support Files/xxx/Photos-Jan-2013" failed: Permission denied (13)
file has vanished: "/cygdrive/E/Users/SharedFiles/3DS STAFF/Reg/2012 - DEAD PROJECTS/2213-xxxxxx&am;C 60x114-5-HR_pdf/xxxxxx 60 x114.5 _HR.pdf"
file has vanished: "/cygdrive/E/Users/SharedFiles/3DS STAFF/Reg/2012 - DEAD PROJECTS/2213-xxxxxx&am;C 60x114-5-HR_pdf/xxxxxx 47 x94_HR.pdf"
Time value of 3DS STAFF/X-employees/xxxxxxx/Jobs- do not remove/1OLD FILES/J-M/Jade/xxxxx logo_cmyk.ai-print on paper.eps truncated on receiver.
Time value of 3DS STAFF/X-employees/xxxxxx/Jobs- do not remove/1OLD FILES/J-M/Jade/xxxx logo_rgb.ai-website.eps truncated on receiver.
file has vanished: "/cygdrive/E/Users/SharedFiles/3DS STAFF/X-employees/xxxxx/Found on iMac/xxxxxx FOLDER/Databases " Presentations " Portfolios/Databases/Database  C .xlsx"
file has vanished: "/cygdrive/E/Users/SharedFiles/CURRENT FILES/12050 - xxxxx Canada - xxxxx National Park/ARTWORK DRAWINGS/xxxxx Graphic Layouts/Batch 4 pdfs for Trish/kathy's Batch 4 pdfs for xxxxx/Links/1 =1' person .eps"
rsync: opendir "/cygdrive/E/Users/SharedFiles/CURRENT FILES/12050 - xxxxx Canada - xxxxx National Park/MANUAL/03_ xxxxx Final Manual_June-2014/ MANUAL FOR CLIENT" failed: Permission denied (13)
rsync: opendir "/cygdrive/E/Users/SharedFiles/CURRENT FILES/12050 - xxxxx Canada - xxxxx National Park/MANUAL/03_ xxxxx Final Manual_June-2014/SECTION 2.0-Exhibits" failed: Permission denied (13)
rsync: opendir "/cygdrive/E/Users/SharedFiles/CURRENT FILES/12050 - xxxxx Canada - xxxxx National Park/MANUAL/03_ xxxxx Final Manual_June-2014/SECTION 7.0_Appendices/Appendix E - Artifact Conservation and Maintenance Manual" failed: Permission denied (13)
1

Use redir to redirect to a new file:

:redir > rsync.log
:g/^rsync/
:redir > file_vanished.log
:g/^file/
:redir END
:q

cat rsync.log
rsync: send_files failed to open "/cygdrive/E/Users/SharedFiles/3DS SALES/3DS MARKETING/PORTFOLIOS/2012 - Portfolios/Signage"XXXXXXXX Full Res photos/xxxxx xx sky/.DS_Store": Permission denied (13)
rsync: opendir "/cygdrive/E/Users/SharedFiles/3DS SALES/CURRENT SALES/Archived Projects/ARCHIVES -xxxxx light/Hootsuite xxxxxx Info" failed: Permission denied (13)
rsync: opendir "/cygdrive/E/Users/SharedFiles/3DS STAFF/Cortney/xxxxx/MANUAL/Support Files/xxx/Photos-Jan-2013" failed: Permission denied (13)
rsync: opendir "/cygdrive/E/Users/SharedFiles/CURRENT FILES/12050 - xxxxx Canada - xxxxx National Park/MANUAL/03_ xxxxx Final Manual_June-2014/ MANUAL FOR CLIENT" failed: Permission denied (13)
rsync: opendir "/cygdrive/E/Users/SharedFiles/CURRENT FILES/12050 - xxxxx Canada - xxxxx National Park/MANUAL/03_ xxxxx Final Manual_June-2014/SECTION 2.0-Exhibits" failed: Permission denied (13)
rsync: opendir "/cygdrive/E/Users/SharedFiles/CURRENT FILES/12050 - xxxxx Canada - xxxxx National Park/MANUAL/03_ xxxxx Final Manual_June-2014/SECTION 7.0_Appendices/Appendix E - Artifact Conservation and Maintenance Manual" failed: Permission denied (13)
2

You can use :redir for this:

                                                        *:redi* *:redir*
:redi[r][!] > {file}    Redirect messages to file {file}.  The messages which
                        are the output of commands are written to that file,
                        until redirection ends.  The messages are also still
                        shown on the screen.  When [!] is included, an
                        existing file is overwritten.  When [!] is omitted,
                        and {file} exists, this command fails.
                        Only one ":redir" can be active at a time.  Calls to
                        ":redir" will close any active redirection before
                        starting redirection to the new target.

So, to capture your desired messages and append them to the current file:

:redir @+
:g/vanished/
:g/send_files/
:g/any_other_regex_you_want/
:redir END
"+P

This will send regex matches to the clipboard register (@+) and then you paste them into the current document: "+P.

  • E475: Invalid argument: +@. I'm using 7.3 on OS X 10.10. – Harv Dec 6 '14 at 21:42
  • @Harv typo: fixed... – jasonwryan Dec 6 '14 at 21:47
  • same error, unfortunately... I think this has something to do with vim on os x and how it interacts with the clipboard, not your solution. Which is a shame! – Harv Dec 6 '14 at 21:50
  • @Harv is vim compiled with clipboard support in OSX? vim --version | awk '/clipboard/ {print $1}' – jasonwryan Dec 6 '14 at 21:54
  • -clipboard. I assume it would be +clipboard if so. So no, I suppose? I didn't compile vim from source, I'm just using what's built-in. – Harv Dec 6 '14 at 21:58
1

You can use the built-in quickfix list to collect all matching lines, with :vimgrep. For example:

:vimgrep /^rsync: / %
:copen

Plugin alternative

My ExtractMatches plugin provides (among others) a :GrepToReg command. With it, you can collect the matching lines in a register and then paste that into a new scratch buffer:

:GrepToReg /^rsync:/
:new | put!
  • Wow! That was really cool but it put in a bunch of text I wasn't interested in (column/line numbers where the regex matched). – Harv Dec 6 '14 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.