I have “input.txt” and I want to search for a string and extract a string between quotes
my input.txt have only 2 lines :
name=' james carter' nationality = ' usa ' age=32
name='fabio rossi' nationality = ' italia - milano ' age=19
I want the batch to extract the names (with spaces) from quotes and put them in variables (in this case only two variables is needed). For example I want to set two variables:
name= james carter
name=fabio rossi
So I can use these variables in batch to do some future maniplation.
ps. its ok to use sed if necessary
edit
it seems to be impossible , so I wonder if can just take the string keeping quotes ,like this
name1=' james carter'
name2='fabio rossi'
so the problem now is,to take what start after name=' and end with '
You can try this:
You will then have enumerated variables (
name1,name2), etc. with the values you want.Note that this works on any line with the specified form (i.e.
name='something' blah blah).EDIT: modified the code to discard lines that don’t contain the string
name=.