Do you know where your variables are? | |
PerlMonks |
Print multiple lines based on conditionby syedasadali95 (Acolyte) |
on Mar 12, 2020 at 07:06 UTC ( [id://11114156]=perlquestion: print w/replies, xml ) | Need Help?? |
syedasadali95 has asked for the wisdom of the Perl Monks concerning the following question: Hi Monks, I am trying to divide one huge file into two files using perl. My source file is something like this ######## file ######## 1. command:read address:0xA 2. command:write address:0xB 3. writedata:0x12 4. writedata:0x34 5. writedata:0x56 6. writedata:0x78 7. command:read address:0xC 8. command:write address:0xD 9. writedata:0x9A 10. writedata:0xBC 11. writedata:0xDE 12. writedata:0xF0 ######## file ######## Taking the above file as input I want to split the content into two different files based on address[0]=0/1. If address[0]=1, I want to print that line to one.txt else print that line to zero.txt no matter whether it is write/read. There is no problem to handle lines of read as it has only one line but the issue here is every write command is followed by next 4 lines of write data. How to print 4 write data lines followed by every write command line to both the output files.
I am struggling here for printing 4 write data lines because my while loop iterates per line and if I am using any loop inside my while loop to print the $line1 variable 4 times then it's printing the same line for 4 times
Back to
Seekers of Perl Wisdom
|
|