Home > Software engineering >  How to deal with "for/f" commands in the DOS batch extraction TXT ignore empty value when
How to deal with "for/f" commands in the DOS batch extraction TXT ignore empty value when

Time:09-27

Test. TXT content is as follows:
Ww 44 dd
22 gg jj
Aa gg xx
Xx tt
Nn
Kk

The separator for the tabs, null value table item margin if separator for a comma, then the following
Ww, 44, dd
22, gg, jj
Aa, gg, xx
Xx,, tt
Nn,,
,,,, kk

I want to use the batch extraction of the second column, and the third column, contain null values, but the results are as follows:
In the second column:
For/f "tokens=2 delims=this is TAB" % % v (d: \ test. TXT) do in echo % % v & gt;> D: \ 3. TXT
Results:
# # # # # # # # # # # # # # # # # # # # # # # #
44
Gg
Gg
Tt - & gt; Here the third fourth line tt came running
# # # # # # # # # # # # # # # # # # # # # # # #
But my ideal results:
# # # # # # # # # # # # # # # # # # # # # # # #
44
Gg
Gg
--> Null value here I just want him to an empty

# # # # # # # # # # # # # # # # # # # # # # # #


In the third column:
For/f "tokens=3 delims=here is tabs" % % v (d: \ test. TXT) do in echo % % v & gt;> D: \ 3. TXT
Results:
# # # # # # # # # # # # # # # # # # # # # # # #
Dd
Jj
Xx - & gt; The tt was taken to the second column below the top a null value, there is no the
# # # # # # # # # # # # # # # # # # # # # # # #
But my ideal results:
# # # # # # # # # # # # # # # # # # # # # # # #
Dd
Jj
Xx
Tt
--> Null value here I just want him to an empty
Kk
# # # # # # # # # # # # # # # # # # # # # # # #

Obvious to ignore, blank value even exist in front of the top of a subsequent value of the phenomenon of blank value
Why will appear this kind of deviation, how can I change, thank each prawn teach ^_^

CodePudding user response:

Xx,, tt
Instead of
xx,,
All right?

CodePudding user response:

Thank you for reply schlafenhamster

At this point, it is not null, there is a space, so the result is certainly can, at the same time, the original place null value will be fill in "the ECHO in the closed state," characters, such as

I will focus on a large number of not I personally Txt data and export file, I will let the original null inserting Spaces unlikely
The result to go to get rid of "the ECHO in the closed state," such a character, too troublesome

Do you have any good Suggestions?

CodePudding user response:

C:\> findstr searches/?
Looking for strings in files.

FINDSTR searches [/B] [/B] [/M] [/R]/[S] [/I] [/X] [/V] [/N] [/M] [/O] [/F: file]
[/C: string] [/G: file] [/D: dir list] [/A: color attributes] [/OFF [the LINE]]
Strings [[drive:] [path] filename [...]]

/B at the beginning of a line matching pattern,
/E at the end of a line matching pattern,
/L by keyword using a search string,
/R will search string used as a general expression,
/S in the current directory search matching files and subdirectories in a directory,
/I specify search case insensitive,
Print completely matching line/X,
Print does not include the matching line/V only,
/N every before printing of the matching rows,
/M if the file contains a match, only print the filename,
/O in each match before character offset printing,
/P ignore file with the nonprintable characters,
/OFF [the LINE] don't skip with offline file attributes,
/A: attr hexadecimal digits are destined to color attribute, please see the "color/?"
/F: file read file list from the specified file (/on behalf of the console),
/C: string using the specified string as a text search string,
/G: file get search string from the specified file, (/on behalf of the console),
/D: dir find a semicolon as separators directory list
Strings to find words,
[drive:] [path] filename
To find the specified file,

Prefix unless parameters have a/C, please use the space separated by a search string,
For example: 'FINDSTR searches "hello there" x.y' seeking "hello" or in file x.y
"There," 'FINDSTR searches/C: "hello there" x.y' file x.y looking for
"Hello there,"

The general expression of quick reference:
Wildcard: any characters
* repeat: characters or number of categories of zero or more than zero before
^ line location: the beginning of a line of
$row position: the end
Categories: [class] characters in any character set characters
[^ class] fill character categories: any character not in the character set
Scope: x-y in any character within the specified range
\ x Escape: metacharacters word usage of x
\ & lt; Xyz position: words start
Xyz \ & gt; Location: the end of the word is

About the FINDSTR searches the common expression of the details, please see online command reference,
  • Related