I am using the following sed command to find a string in between patters for each file in a folder, files are named 01.txt, 02.txt etc.:
sed -n '/PAT1/,/PAT2/{/PAT1/!{/PAT2/!p}}' * >> file
but the output is not sorted by the same order of files in the directory, rather by some other order. I did try to pipe out to sort but the order is then spread across ALL matches/All files which is not what I am looking for. I want the output to be appended in the same 01.txt, 02.txt order. I've seen grep doing the same, finding matches and jumping from one file to another. I prefer using sed but grep is an option. thanks.
sort
command. maybe you want to run sort, after you generate your file, IDK.man sort
will give you some more options. Posting a sample of your input, or output could be useful to us, if you want something sorted in a more specific way.