Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
enemyofman
- Posts: 3
- Joined: 28 Oct 2015 05:00
#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
#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
#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
#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\"