batch file - How to extract, using cmd, string between quotes from a particular line -


hope clear problem , search for. have long script in .sjs file (basically txt different extension), part of following lines. in comments below either referred input.txt or builder.sjs

var want_spring_aid_file_update = 0; var front_spring_aid_file = "name_1.pspck"; var rear_spring_aid_file = "name_2.pspck"; 

i have been looking around .bat script can probe lines, 2 , 3 in case above, in .sjs file , write string between double quotes in text new file. in comments below new text file referred comments.txt.

i have found on marvelous website script outputs strings between quotes in file. want on particular lines. script talking below.

>"output.txt" (  /f usebackq^ tokens^=2^ delims^=^" %%a in ("input.txt") echo "%%a"  ) 

also helpful me understand role of characters in above script. these ^, 2^, ^=^.

thanks guys !

the command for option /f used process lines of file, or single string specified in double quotes, or output of command line executed for in separate command process in background captured handle stdout of background command process.

the first option usebackq results in interpreting file name specified in double quotes not string process, double quoted name of file of lines should processed for.

the option delims= used specify delimiters splitting each non empty line not starting default end of line character ; 1 or more substrings called tokens. default delimiters space , horizontal tab character. delims= without character means not split line @ all. double quote character " should used task delimiter.

the option tokens= defines substring(s) should assigned loop variable(s). default first substring (token) assigned specified loop variable. specifying tokens=2 command for informed of interest second substring should assigned specified loop variable (first). means if line not have string after 1 or more of specified delimiters, line ignored. true first line of input.txt not contain double quote character @ all.

run in command prompt window for /? more information options of command for output on several pages.

those options of for specified enclosed in double quotes.

>"output.txt" (     /f "usebackq tokens=2 delims="" %%a in ("input.txt") echo "%%a"  ) 

but problem here specifying " delimiter. windows command interpreter option string "usebackq tokens=2 delims=" not make sense because means lines should not split tokens , nevertheless second token of interest. however, next " invalid because expected next loop variable, single character percent sign before. percent sign must escaped in batch file additional percent sign.

for reason necessary specify options of for without enclosing them in double quotes. must made sure during preprocessing phase of windows command interpreter before executing for command line 3 options interpreted single argument string.

the escape character use in batch files caret character ^ instructs windows command interpreter interpret next character literal character belonging argument string. % must escaped % instead of ^ interpreted literal character.

it can read on running in command prompt window cmd /? on last paragraph on last output page characters in directory/file names (or other argument strings) require enclosing string in double quotes: space character, characters &()[]{}^=;!'+,`~ , not mentioned characters "|<> can't used in directory/file name.

so specified usebackq^ tokens^=2^ delims^=^" windows command interpreter argument string not enclosed in double quotes unusual text usebackq tokens=2 delims=" should passed command for second argument after /f.

windows command interpreter interprets space character , equal sign not escaped ^ delimiter between argument strings.

a double quote not escaped ^ interpreted begin of argument string ends double quote , characters between exception of % , ! when delayed expansion enabled interpreted literal characters.

that reason why spaces characters, equal signs , double quote must escaped ^ in argument string usebackq tokens=2 delims=".

see how windows command interpreter (cmd.exe) parse scripts? more detailed information command line parsing windows command interpreter.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -