This questions has been asked before, except they were looking for text between two dates including or excluding those dates. Ive changed one of the answers so that it selects and includes from first date and goes to but excludes the second date (I think/hope). However I don't understand where you provide the text file in which to apply this to? set - date1 date2 junk  from=$1till=$2file=$3  # Output lines between two parameter dates # INCLUDING the first parameter date but not the secondawk -v from=$from -v till=$till '    ($2 >= from) && ($2 < till) { print $0 ; next }    ($2 >= till) { exit }' $fileSince discovering a clumpy solution, I've realized that there's another aspect that would improve this, and prevent me from having to write slight changes of the script line many times over. Current working solution is:awk '/^date_1_/,/^date_2_/ {print}' file.txt > file2.txtgrep -v date_2_ file2.txt > file2tmp.txtmv file2tmp.txt file2.txtHowever I would like it to do this for every new date. e.g. select text from Date_1_ (including date_1_) up to but not including Date_2_, then select text from Date_2_ to 3 in the same way, 3 to 4 in the same way (all the way to 1000). Is there a solution I can easily scale up?Example input text file (though actual file goes up to 1000, also there are not spaces between the underscores in the txt file but i dont have a back tick to escape there italic effects):' > _ 1_ fe fi fo fum >_ 2_ beep bap bop >_ 3_ ti fi at atExample Output:created text file1: > _ 1_ fe fi fo fumcreated text file2: >_ 2_ beep bap bopcreated text file3: >_ 3_ ti fi at at  
Output lines between two parameter dates INCLUDING the first parameter date but not the second
text processing;awk
If I understand the current state of this constantly moving question correctly, you have a file with an arbitrary number of lines, divided into sections marked by something like _1_ to _1000_, and you would like to split those sections into individual files. If so, then csplit can do that: csplit file.txt '/^_[0-9]\+_/' '{*}'