Reputation: 39
I have one file with 31899 line and I only want to print string betwwen [] symbols how can I do that.I only want test and test 2 strings.
[TEST]
var=15
[TEST2]
dex=78
Upvotes: 0
Views: 208
Reputation: 804
GNU awk-specific solution:
gawk 'match($0,/^\[(.*)\]/, ary) { print ary[1]}' < yourFile
Upvotes: 0
Reputation: 79983
for /f "delims=[]" %%a in ('find "[" "filename" ') do echo %%a
(as a batch line - reduce each %%
to %
to run directly from the prompt)
for every line that contains [
, extract the first token delinted by the two nominated characters.
Assumes all instances of [
are as shown in the sample.
Upvotes: 0
Reputation: 38589
There were a couple of small errors in Magoo's answer, try one of these instead.
Batch File, (current directory contains artmd.ini):
@For /F "Delims=[]" %%A In ('Find "["^<"artmd.ini"') Do @Echo=%%A
Command prompt, (current directory contains artmd.ini):
For /F "Delims=[]" %A In ('Find "["^<"artmd.ini"') Do @Echo=%A
Upvotes: 1