insert line in file every 1000th line via sed or in vi
Hi all,
you helped me out once and I hope you can do it once again.;) My problem: I have a more or less big file with many update statements (about 590000)for execution in an Oracle database. Now I need to insert a "commit" line after every 1000th line. Do you have any idea to do this with 'sed' or directly in 'vi'? Thanks in advance for your help. Best regards Elke |
Some versions of sed can do it.
Code:
sed -e '0~5 s/$/\nfoo/' first~stepOtherwise, if you need something portable, you could try awk Code:
awk '{print;} !(++a%5) {print "foo";}' |
@Turbocapitalist:
thanks a lot. The second advice (awk) did it. sed replaced each fifth line with "commit" instead of inserted it. Best Regards Elke |
Strange. sed should do the job. Which regex did you write? Or did you work with the 'a' command instead?
|
I used
sed -e '0~5 commit;' test.sql > test1.sql and in test1.sql where the same amount of lines as in test.sql but each fifth row was replaced by commit. :scratch: |
Ah. You missed the actual sed command: 'a'
Code:
sed -e '0~5 acommit;' test.sql > test1.sql |
Without the a (append) it becomes a c (change) followed by the string "ommit".
|
All times are GMT -5. The time now is 02:39 PM. |