Re: vim | multiple files editing and delete question
Nikolaos A. Patsopoulos wrote: Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: 2.Can I delete after a pattern search? Sth like this: :/^html\_.{-}body: /-3d and how can I repeat this globally? :g/^html\_.{-}body: /.-3d Yakov I get an E16: invalid range error Yeah, this can happen if pattern is found in line number 4. (Then .-3 results in =0 which is invalid line number). Just insert 4 dummy empty lines at beginning of file to avoid this. Yakov This means that the -3d counts from the beginning of the pattern?? In my file The first occurrence of the patten expands from line 1 to line 82. Yes, from the beginning of the pattern Yakov How can I force it to delete 3 lines from the end? Disclaimer: Everything below is untested. Normally, an HTML page should have only one BODY tag. The following should do (without :g) :1|/\cbody\/-3d If you may have, before HTML, a BODY which mustn't trigger a deletion: :1|/\c\@=html\/;/\cbody\/-3d If (your original command) you may have several HTML tags in a single file, and the single line 3 lines above the next BODY tag must be deleted... well, I think it's doable but I won't venture a command. Note: \c in a pattern means disregard case, \ means end-of-word, x\@= means if preceded by x. The latter is used here (in the second example) to avoid missing HTML at the start of line 1. Best regards, Tony.
Re: vim | multiple files editing and delete question
Tim Chase wrote: To do an operation on multiple files in a WinXP DOS batch: for %%A in (*.txt) do [command] Just a small caveat to the reader, this works within a batch file by escaping the variable (%A in this case). If you're running it from the command-line, you don't escape it, and thus use for %a in (*.txt) do [command using %a] instead of for %%a in (*.txt) do [command using %%a] Then again, maybe I'm among the freakish few that actually use for-loops at the dos-prompt. :) -tim I have used them too, starting (in my case) with Dos 3.1. Your warning is valid on old DOS shells, and is regarded as good form writing by old hands like me, but IIRC, with modern versions of CMD.EXE, and with NDOS.EXE, 4DOS.EXE or 4NT.EXE, you may use either %a or %%a in either the command line or a batch file. Best regards, Tony.
Re: vim | multiple files editing and delete question
for %a in (*.txt) do [command using %a] instead of for %%a in (*.txt) do [command using %%a] Then again, maybe I'm among the freakish few that actually use for-loops at the dos-prompt. :) -tim I have used them too, starting (in my case) with Dos 3.1. Your warning is valid on old DOS shells, and is regarded as good form writing by old hands like me, but IIRC, with modern versions of CMD.EXE, and with NDOS.EXE, 4DOS.EXE or 4NT.EXE, you may use either %a or %%a in either the command line or a batch file. As tested under cmd.exe on WinXP: : C:\Tempver Microsoft Windows XP [Version 5.1.2600] C:\Tempcopy con x.bat @echo off for %f in (*.*) do @echo %f ^Z 1 file(s) copied. C:\Tempx.bat f was unexpected at this time. C:\Temp REM check to see if it's particular to bat vs. cmd C:\Tempren x.bat x.cmd C:\Tempx.cmd f was unexpected at this time. C:\Tempfor %%f in (*.*) do @echo %%f %%f was unexpected at this time. C:\Tempfor %f in (*.*) do @echo %f [directory listing] C:\Tempcopy con x.bat @echo off Overwrite x.bat? (Yes/No/All): y for %f in (*.*) do @echo %f ^Z 1 file(s) copied. C:\Tempx.bat [directory listing] : batch files do require the double percent-sign and using for-loops on the command line directly requres a single percent-sign. Couldn't tell you about other shells. I haven't used 4dos since I last booted my Compaq 386SX/16 (a good 4-5 yrs ago) which is currently serving a critical role as 3 of monitor support...but it runs the dos version of vim :) -tim
Re: vim | multiple files editing and delete question
On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: Hi, I have a series of questions: 1. I want to edit multiple files from command line so I created a vim script with all the commands (20). I use a batch file in WinXP: |@echo off vim -s script file.txt exit however I need to run this script on multiple files. In vim's help there is this code for use in bash(?) shell ||for file in *.txt; do| | vim -e -s $file change.vim| If you want to read vim commands from change.vim, then try: vim -e -s -c 'so change.vim' $file Also: :help argdo Yakov
Re: vim | multiple files editing and delete question
On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: 2.Can I delete after a pattern search? Sth like this: :/^html\_.{-}body: /-3d and how can I repeat this globally? :g/^html\_.{-}body: /.-3d Yakov
Re: vim | multiple files editing and delete question
On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: 3. This is not Vim related but I wonder if anyone knows sth. I have the following structure of folders and files: .. folder1 file1 file2 folder2 file1 file2 . and want to add the folder name into the filename: || folder1 ||folder1|_|file1 ||folder1|_|||file2 folder2 ||folder2|_|||file1 ||folder2|_|||file2 Try this shell script: for file in folder*/*; do dir=$(basename $(dirname $file) ) base=$(basename $file) mv $file $(dirname $file)/${dir}_${base} done Untested! Yakov
Re: vim | multiple files editing and delete question
Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: 2.Can I delete after a pattern search? Sth like this: :/^html\_.{-}body: /-3d and how can I repeat this globally? :g/^html\_.{-}body: /.-3d Yakov I get an E16: invalid range error -- Nikolaos A. Patsopoulos, MD Department of Hygiene and Epidemiology University of Ioannina School of Medicine University Campus Ioannina 45110 Greece Tel: (+30) 26510-97804 mobile: +30 6972882016 Fax: (+30) 26510-97867 (care of Nikolaos A. Patsopoulos) e-mail: [EMAIL PROTECTED]
Re: vim | multiple files editing and delete question
On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: 2.Can I delete after a pattern search? Sth like this: :/^html\_.{-}body: /-3d and how can I repeat this globally? :g/^html\_.{-}body: /.-3d Yakov I get an E16: invalid range error Yeah, this can happen if pattern is found in line number 4. (Then .-3 results in =0 which is invalid line number). Just insert 4 dummy empty lines at beginning of file to avoid this. Yakov
Re: vim | multiple files editing and delete question
On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: 2.Can I delete after a pattern search? Sth like this: :/^html\_.{-}body: /-3d and how can I repeat this globally? :g/^html\_.{-}body: /.-3d Yakov I get an E16: invalid range error Yeah, this can happen if pattern is found in line number 4. (Then .-3 results in =0 which is invalid line number). Just insert 4 dummy empty lines at beginning of file to avoid this. Yakov This means that the -3d counts from the beginning of the pattern?? In my file The first occurrence of the patten expands from line 1 to line 82. Yes, from the beginning of the pattern Yakov
Re: vim | multiple files editing and delete question (bash script)
On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: 3. This is not Vim related but I wonder if anyone knows sth. I have the following structure of folders and files: .. folder1 file1 file2 folder2 file1 file2 . and want to add the folder name into the filename: || folder1 ||folder1|_|file1 ||folder1|_|||file2 folder2 ||folder2|_|||file1 ||folder2|_|||file2 Try this shell script: for file in folder*/*; do dir=$(basename $(dirname $file) ) base=$(basename $file) mv $file $(dirname $file)/${dir}_${base} done Untested! Yakov Bash result: script started, file is typescript. Nothing happens. Just an empty file called typescript appears in parent folder. Try on bash mailing list or bash irc chan. Yakov
Re: vim | multiple files editing and delete question
Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: 2.Can I delete after a pattern search? Sth like this: :/^html\_.{-}body: /-3d and how can I repeat this globally? :g/^html\_.{-}body: /.-3d Yakov I get an E16: invalid range error Yeah, this can happen if pattern is found in line number 4. (Then .-3 results in =0 which is invalid line number). Just insert 4 dummy empty lines at beginning of file to avoid this. Yakov This means that the -3d counts from the beginning of the pattern?? In my file The first occurrence of the patten expands from line 1 to line 82. Yes, from the beginning of the pattern Yakov How can I force it to delete 3 lines from the end? -- Nikolaos A. Patsopoulos, MD Department of Hygiene and Epidemiology University of Ioannina School of Medicine University Campus Ioannina 45110 Greece Tel: (+30) 26510-97804 mobile: +30 6972882016 Fax: (+30) 26510-97867 (care of Nikolaos A. Patsopoulos) e-mail: [EMAIL PROTECTED]
Re: vim | multiple files editing and delete question (bash script)
Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: 3. This is not Vim related but I wonder if anyone knows sth. I have the following structure of folders and files: .. folder1 file1 file2 folder2 file1 file2 . and want to add the folder name into the filename: || folder1 ||folder1|_|file1 ||folder1|_|||file2 folder2 ||folder2|_|||file1 ||folder2|_|||file2 Try this shell script: for file in folder*/*; do dir=$(basename $(dirname $file) ) base=$(basename $file) mv $file $(dirname $file)/${dir}_${base} done Untested! Yakov Bash result: script started, file is typescript. Nothing happens. Just an empty file called typescript appears in parent folder. Try on bash mailing list or bash irc chan. Yakov Thanks. I'll do that. Nikos
Re: vim | multiple files editing and delete question
On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: Yakov Lerner wrote: On 9/14/06, Nikolaos A. Patsopoulos [EMAIL PROTECTED] wrote: 2.Can I delete after a pattern search? Sth like this: :/^html\_.{-}body: /-3d and how can I repeat this globally? :g/^html\_.{-}body: /.-3d Yakov I get an E16: invalid range error Yeah, this can happen if pattern is found in line number 4. (Then .-3 results in =0 which is invalid line number). Just insert 4 dummy empty lines at beginning of file to avoid this. Yakov This means that the -3d counts from the beginning of the pattern?? In my file The first occurrence of the patten expands from line 1 to line 82. Yes, from the beginning of the pattern Yakov How can I force it to delete 3 lines from the end? This is tricky, but try this: :g/pattern/exe normal //e|.-3d (untested) Yakov
Re: vim | multiple files editing and delete question
On Thu, 2006-09-14 at 13:01 +0300, Nikolaos A. Patsopoulos wrote: 1. I want to edit multiple files from command line so I created a vim script with all the commands (20). I use a batch file in WinXP: |@echo off vim -s script file.txt exit however I need to run this script on multiple files. In vim's help there is this code for use in bash(?) shell ||for file in *.txt; do| | vim -e -s $file change.vim| | lpr -r tempfile| |done however it doesn't seem to work under Cygwin. To do an operation on multiple files in a WinXP DOS batch: for %%A in (*.txt) do [command] Chain multiple commands after the do statement with : for %%A in (*.txt) do vim -e -s change.vim %%A copy %%A lpt1 or call a separate batch that takes %1 as the argument: for %%A in (*.txt) do call MyEdit.bat %%A where MyEdit.bat is: @echo OFF echo File %1... vim -e -s change.vim %1 copy %1 lpt1 Note that I usually sprinkle double quotes liberally to avoid issues with spaces in paths. -- Steve Hall [ digitect dancingpaper com ]
Re: vim | multiple files editing and delete question
Steve Hall wrote: On Thu, 2006-09-14 at 13:01 +0300, Nikolaos A. Patsopoulos wrote: 1. I want to edit multiple files from command line so I created a vim script with all the commands (20). I use a batch file in WinXP: |@echo off vim -s script file.txt exit however I need to run this script on multiple files. In vim's help there is this code for use in bash(?) shell ||for file in *.txt; do| | vim -e -s $file change.vim| | lpr -r tempfile| |done however it doesn't seem to work under Cygwin. To do an operation on multiple files in a WinXP DOS batch: for %%A in (*.txt) do [command] Chain multiple commands after the do statement with : for %%A in (*.txt) do vim -e -s change.vim %%A copy %%A lpt1 or call a separate batch that takes %1 as the argument: for %%A in (*.txt) do call MyEdit.bat %%A where MyEdit.bat is: @echo OFF echo File %1... vim -e -s change.vim %1 copy %1 lpt1 Note that I usually sprinkle double quotes liberally to avoid issues with spaces in paths. That works great!!! Thanks! Nikos
Re: vim | multiple files editing and delete question
To do an operation on multiple files in a WinXP DOS batch: for %%A in (*.txt) do [command] Just a small caveat to the reader, this works within a batch file by escaping the variable (%A in this case). If you're running it from the command-line, you don't escape it, and thus use for %a in (*.txt) do [command using %a] instead of for %%a in (*.txt) do [command using %%a] Then again, maybe I'm among the freakish few that actually use for-loops at the dos-prompt. :) -tim
RE: vim | multiple files editing and delete question
If u have Cygwin then creating a batch file with the following would be the simplest solution - set TARGETDIR=C:\something set SCRIPTDIR=C:\something_else find %TARGETDIR% -name *.[ch] -exec gvim -s %SCRIPTDIR%\win32_vimscript.vim {} ; Basically use find to help u (actually it's just one instruction, so u don't even need to have a batch file for it) Regards, Sibin -Original Message- From: Nikolaos A. Patsopoulos [mailto:[EMAIL PROTECTED] Sent: Thursday, September 14, 2006 3:31 PM To: vim@vim.org Subject: vim | multiple files editing and delete question Hi, I have a series of questions: 1. I want to edit multiple files from command line so I created a vim script with all the commands (20). I use a batch file in WinXP: |@echo off vim -s script file.txt exit however I need to run this script on multiple files. In vim's help there is this code for use in bash(?) shell ||for file in *.txt; do| | vim -e -s $file change.vim| | lpr -r tempfile| |done however it doesn't seem to work under Cygwin. 2.Can I delete after a pattern search? Sth like this: :/^html\_.{-}body: /-3d and how can I repeat this globally? 3. This is not Vim related but I wonder if anyone knows sth. I have the following structure of folders and files: .. folder1 file1 file2 folder2 file1 file2 . and want to add the folder name into the filename: || folder1 ||folder1|_|file1 ||folder1|_|||file2 folder2 ||folder2|_|||file1 ||folder2|_|||file2 Thanks in advance, Nikos | - Disclaimer - This message(including attachment if any)is confidential and may be privileged.Before opening attachments please check them for viruses and defects.MindTree Consulting Private Limited (MindTree)will not be responsible for any viruses or defects or any forwarded attachments emanating either from within MindTree or outside.If you have received this message by mistake please notify the sender by return e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited. Please note that e-mails are susceptible to change and MindTree shall not be liable for any improper, untimely or incomplete transmission. -
Re: vim | multiple files editing and delete question
Sibin P. Thomas wrote: If u have Cygwin then creating a batch file with the following would be the simplest solution - set TARGETDIR=C:\something set SCRIPTDIR=C:\something_else find %TARGETDIR% -name *.[ch] -exec gvim -s %SCRIPTDIR%\win32_vimscript.vim {} ; Basically use find to help u (actually it's just one instruction, so u don't even need to have a batch file for it) Regards, Sibin -Original Message- From: Nikolaos A. Patsopoulos [mailto:[EMAIL PROTECTED] Sent: Thursday, September 14, 2006 3:31 PM To: vim@vim.org Subject: vim | multiple files editing and delete question Hi, I have a series of questions: 1. I want to edit multiple files from command line so I created a vim script with all the commands (20). I use a batch file in WinXP: |@echo off vim -s script file.txt exit however I need to run this script on multiple files. In vim's help there is this code for use in bash(?) shell ||for file in *.txt; do| | vim -e -s $file change.vim| | lpr -r tempfile| |done however it doesn't seem to work under Cygwin. 2.Can I delete after a pattern search? Sth like this: :/^html\_.{-}body: /-3d and how can I repeat this globally? 3. This is not Vim related but I wonder if anyone knows sth. I have the following structure of folders and files: .. folder1 file1 file2 folder2 file1 file2 . and want to add the folder name into the filename: || folder1 ||folder1|_|file1 ||folder1|_|||file2 folder2 ||folder2|_|||file1 ||folder2|_|||file2 Thanks in advance, Nikos | - Disclaimer - This message(including attachment if any)is confidential and may be privileged.Before opening attachments please check them for viruses and defects.MindTree Consulting Private Limited (MindTree)will not be responsible for any viruses or defects or any forwarded attachments emanating either from within MindTree or outside.If you have received this message by mistake please notify the sender by return e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited. Please note that e-mails are susceptible to change and MindTree shall not be liable for any improper, untimely or incomplete transmission. - No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.1.405 / Virus Database: 268.12.3/447 - Release Date: 13/9/2006 Haven't tested your suggestion, but this works just fine: for file in folder */*; do dir=$(basename $(dirname $file)) base=$(basename $file) mv $file $(dirname $file)/${dir}_${base} done