Sunday, 15 June 2014

regex - Name of input file in replacement output of stream editor? -



regex - Name of input file in replacement output of stream editor? -

i have list of files pass sed:

echo abc > test0; echo cab > test1; echo xyz > test2

i need have grouping captured and filename in output of sed like

$ cat test0 test1 test2 | sed -e 's/(\b[abc]+\b)/found \1 in file \?/' found abc in file ? found cab in file ? xyz

with question marks replaced respective filenames. possible? if yes, how :d

thanks in advance

edit: know can have simply

grep -e '(\b[abc]+\b)' test0 test1 test2

but need own output generate code in language

i utilize loop. can utilize bash:

for in test0 test1 test2; sed -e "s/(\b[abc]+\b)/found \1 in file $i/" "$i" done

regex bash sed

No comments:

Post a Comment