May. 15th, 2009

lovingboth: (Default)
A bash script I use ends by displaying a line it wants you to add to another file. It would obviously be easier if the script did this itself. As the line will be somewhere in the middle of the file, just using '>>' to append it is no good.

Somewhere :) I have (or had) The AWK Programming Language and my Google skills are enough to be reminded that:

awk '/NEW STUFF HERE/ {print;print "my new line";next}1' test-file


will add 'my new line' after 'NEW STUFF HERE'.

Now, 'my new line' needs to have a number in it that is different to all the other such lines (it's an array index).

Can someone remind me of a good way to do that? The line count of the entire file prior to adding the line would be fine, for example.

Profile

lovingboth: (Default)
Ian

November 2025

S M T W T F S
      1
2 345678
910 1112 131415
16 1718192021 22
23242526 272829
30      

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags