I'm really close to getting this right, I think, but is one nuance eluding me, so I'm going to ask here.
I'm trying to number lines in a file -- but ONLY certain lines. Example:
Code:
bash$ cat file.txt
1 important line
blah blah blah
2 important line
blah blah blah
3 important line
etc etc etc
I seem to be able to get sed and awk to grab only the important lines and number them, but I can't re-integrate those lines back into the file; ergo, I get:
Code:
bash$ cat file.txt | sed '/\<important/!d' | awk '{gsub(/\<important/,(x +=1));print}'
1 important line
2 important line
3 important line
I can also get sed alone to print the actual line numbers on just the important lines, but they obviously are the real line numbers and I'd prefer them to be numbered 1-whatever, sequentially, regardless of where they actually fall in the document.
Any ideas? I'm not married to sed or awk, so if it's a perl command or something, that works too.