Copying files with specific string inside

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
enemyofman
Posts: 3
Joined: 28 Oct 2015 05:00

Copying files with specific string inside

#1 Post by enemyofman » 28 Oct 2015 05:16

hi,
i don't use batch very often and i have a problem: i want to copy some files from one folder to another. not all of them but only the ones with specific strings inside. all files have similiar structure:

Code: Select all

AA|(data)|(data)|(data)|(data)
AB|(data)|(data)|(IMPORTANT)|(data)
AC|(data)|(data)|(data)|(data)

i want to copy only that files that in line AB we have string "archive" in IMPORTANT field.

how to do this?

Squashman
Expert
Posts: 4487
Joined: 23 Dec 2011 13:59

Re: Coping files with specific string inside

#2 Post by Squashman » 28 Oct 2015 06:43

You are showing us extremely obfuscated data. Your data example does not even match your description. Your AB line does not say archive in it at all. What I believe you are trying to communicate is the word archive appears in the 4th pipe delimited field of your data.

Will archive be the only word in this field?
Are there always parentheses surrounding each field?

enemyofman
Posts: 3
Joined: 28 Oct 2015 05:00

Re: Coping files with specific string inside

#3 Post by enemyofman » 28 Oct 2015 06:53

sorry, you're right, example data for AB line should look like this:

AB|5b|22.10.2015|archive|Duplicate items


"archive" will be only word in this filed. "|" are delimiters of the data.
there are no parentheses in every field (but they may apear somewhere)

Squashman
Expert
Posts: 4487
Joined: 23 Dec 2011 13:59

Re: Coping files with specific string inside

#4 Post by Squashman » 28 Oct 2015 07:42

Code: Select all

@echo off
FOR /F "delims=" %%G in ('findstr /m /br "AB|[^|]*|[^|]*|archive|" *.txt') DO COPY "%%~G" "C:\some folder\path\"

enemyofman
Posts: 3
Joined: 28 Oct 2015 05:00

Re: Copying files with specific string inside

#5 Post by enemyofman » 28 Oct 2015 08:26

thank you - it works perfect!

Post Reply