in reply to Re^2: Insert blank rows in a CSV
in thread Insert blank rows in a CSV
One nice property of this approach is that if your script bombs in the middle, you still have the original contents around. So, I hope this explains why you don't have to "reserve" space in your original file for the added content.
On the other hand, if you want your original file to actually look like:
and you want the script to replace<---Start of the CSVFILE -----------------------------> <--Here goes a image ---------------------------------> <--Here goes a blank row -----------------------------> <--Here goes the header ------------------------------> 123456 123 john 9393939 data data 123456 123 john 9393939 data data 123456 123 john 9393939 data data 123456 123 john 9393939 data data 123456 123 john 9393939 data data
with something, then that's a different problem, but you can still use the same idea:<--Here goes a image --------------------------------->
Use the above code with the -i option to use perl's file editing feature. If the rows you want to replace are blank, then just use line numbers as the matching criteria:while (<>) { if (m/^<--Here goes a image.../) { print ...whatever... } else { print; } }
while (<>) { if ($. == 2) { print ...image csv line... } else { print; } }
|
|---|