1

I want to retrieve whatever is between these two tags <data ... - </ data> and export each result in a separate text file This command works very well, but unfortunately output is one file :-(

sed -n '/<data*/,/<\/data>/p' Input.txt > Output.txt

Do you have any suggestion for this?

Thanks

2
  • 1
    Please supply a sample input file.
    – fpmurphy
    Commented Mar 26, 2021 at 3:01
  • Please provide example Commented Mar 27, 2021 at 8:04

1 Answer 1

1

You can get the results into separate containers if we forward the sed o/p to csplit

sed -e '/<report>/,\|</report>|!d' input.txt |
csplit -s -z -f Output -  '/<\/report>/+1' '{*}'
  • Depending on the file input, you will see Output00, Output01,...
  • The splitting is done on the line following the regex

Not the answer you're looking for? Browse other questions tagged .