I have a file which has bunch of lines which starts from a fixed pattern and ends with another fixed pattern.
I want to make use of these fixed starting and ending patterns to select the bunch, one at a time.
I tried using awk '/Hi welcome/,/Bye**/' inputfile.txt to select text from Hi welcome to Bye** However, it selects complete document may be because even whole document starts with "Hi welcome" and ends with "Bye**". Here I am trying to get it block by block (From Hi welcome to Bye** is one block) in a temp file by using for loop.
I don't think you can use awk to process parts of files in a loop, at least not without additional measures. Try this suggestion to create several .tmp files that you can loop through afterwards:
Hi Pamu, once i pressed "Enter" key it returned to $ prompt without giving any output on screen.
Hi Rudic, the solution that you have given is working fine but I have more than a million records ka file to process. So its difficult to follow your suggestion. Any better way of doing it.
If you don't have any escape sequence in "blah blah blah", try this (made in bash):
par=""
while IFS= read line; do
par="${par}${line}\n"
if [ "$line" = "Bye**" ]; then
par=${par%\\n}
echo -e "${par}" >tmpfile
cat tmpfile # or do whatever you like with it
par=""
fi
done <inputfile
Sorry, it may sound foolish but may I know where to enter input file name and what will be output file name? Also, wondering where is "Bye**" pattern is placed in the script.
Sorry, the input filename I used is "test" - pls replace. The ouput is sent to stdout, you can use the redirection ">" to send it to e.g. "tempfile" or whatever filename you like. We dont need the "Bye**" pattern if the input file is structured like you posted: "Bye**" immediately followed by the next "Hi welcome".