Hello, i'm trying to write a script, that goes through a file, that has entries like: 1_ftp 2_ftp 3_ftp 1_1ftp 2_1ftp 3_1ftp 1_2ftp 2_2ftp ... Now i want to add an entry like "4_ftp" , but only after the "3_ftp". That's why ""echo "4_ftp" >> file" won't work. So how could i solve this issue?
you have probably already thought of this, but dismissed it due to its lack of 'elegence' but if I needed to get the job done, I would: write all of those values into an array using explode(). using carriage return delimiter, either with a while/for or foreach loop keep writing the lines into a new file until you get where you want to be(continually checking with an if statement). then write in a new line, and continue along the previous loop. So by the end of it you should have a file that is almost identical to your original file. Then you can over write the old file with the new one. As i said, not elegant, but it should work with relatively known commands.