| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
The windows build in DIR command is the equivalent to the unix find utility.
Both process the file/folder structure of a drive.
The windows build in FIND command searches for a string inside a file
and is a weak version of the build in FINDSTR command.
FINDSTR is a very week "equivalent" to sed.
Tim intended to search the directory for the appropiate files and then
use sed to delete the lines.
This can be done with DIR - but only inside a loop.
For a single file you can use the TYPE command and pipe the output to sed.
Example: TYPE "file"|sed "do something" > outputfile.bak or TYPE
"file"|sed -i.bak "do something"
Here are two example batch files following Tims suggestion.
Batch1 recurses all subdirectories without DIR.
FOR /R is the most reliable way to loop if you're in need to search all
subdirectories for files.
The TYPE command is necessary to show contents of a file inside console.
Batch2 uses the DIR command inside a FOR loop to specify your search
options.
This method is much more error sensitive.
--- start batch1 ----
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
:: you may delete the ECHO lines
:: to get more info about usage of "FOR" or "TYPE"
:: type for /? or type /? inside console
:: walk through all subdirectories of %CD% (current path)
FOR /R "%CD%" %%a in (test*.txt) DO (
ECHO "%%a"
TYPE "%%a"|usr\local\wbin\sed "1,9d" > %CD%\%%~na.bak
ECHO.
)
CMD /K&ENDLOCAL
--- end batch1 ----
--- start batch2 ----
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
:: you may delete the ECHO lines
:: "delims= " = "delims=[tab][space][tab]" (needed to prevent
splitting of file/dir names with spaces)
:: DIR /B = short output format
:: /S = process subdirs
:: /A:-D = Option: list files only (no directories)
:: %%~na.bak = substitute filename (show filename without extension)
FOR /F "delims= " %%a IN ('DIR /B /S /A:-D "%CD%\test*.txt"') DO (
ECHO "%%a"
TYPE "%%a"|usr\local\wbin\sed "1,9d" > %%~na.bak
ECHO.
)
CMD /K&ENDLOCAL
--- end batch ----
Zharif
Am 04.11.2014 um 12:32 schrieb Rafael [email protected] [sed-users]:
> didnt work, but thanks.
>
>
> I think the find from windows is screwing it.
>
>
> On Mon, Nov 3, 2014 at 9:47 PM, Tim Chase [email protected] [sed-users] <
> [email protected]> wrote:
>
>
>>
>> On 2014-11-03 11:10, [email protected] [sed-users] wrote:
>>> Hi,
>>> How can I delete lines in files in subfolders? Im using sed for
>>> windows and its not working, Im trying: find E:\emls\*.eml sed -i
>>> "1,9 d"
>>>
>>> Inside emls I have subfodlers with lots of .eml files and i want to
>>> delete the first lines of each file.
>> Usually you'd farm that out to the "find" utility, something like
>>
>> find /path/to/emls -name '*.eml' -exec sed -i.bak 1,9d {} \;
>>
>> This will create ".bak" files which I would want to have around
>> until I'd tested the results. If they worked, you can purge them
>> all (assuming you don't have any other .bak files you want to keep
>> around):
>>
>> find /path/to/emls -name '*.eml.bak' -delete
>>
>> -tim
>>
>>
>>
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
> ------------------------------------
> Posted by: Rafael <[email protected]>
> ------------------------------------
>