Sample Header Ad - 728x90

Read file till special char, copy that section into another file, and continue till eof

0 votes
3 answers
99 views
I am trying to read a file in Linux and as soon as a "&" character is encountered, I am writing the output to another file, sending that file to another folder and then continuing to read the original file till next "&" and so on Input xml file-
&




&
My code snippet -
while IFS= read -r line;do
     if [["$line" =="$delimeter"]];then
         echo "$line" | sed "s/delimeter.*//">> "$output_file"
         cp "$output_file" "$TARGET_FOLDER" 
         break
     else
         echo "$line" >> "$output_file"
     fi
done  to
(till &) section is put in output file, which is copied to TARGET_FOLDER. Then the next
to
section is copied and so on. Thankyou for your help!
Asked by python6 (1 rep)
Oct 11, 2023, 04:34 AM
Last activity: May 20, 2024, 11:16 AM