hi all,
I have a text file with following content
PAGENUMBER
asasasa
asasasa
PAGENUMBER
sasasasasa
PAGENUMBER
using sed i want to replace PAGENUMBER by occurrence count
eg
1
asasasa
asasasa
2
sasasasasa
3
Thanks and Regards,
uttam hoode
sank
2
why not use awk, try this:
cat $filename | awk '/PAGENUMBER/{count++; { sub("PAGENUMBER",count, $0)}; }; {print }'
A part of this command is taken from a similar post by lyoncc, thanks to lyoncc.
awk '/PAGENUMBER/{print ++i;next}1' file
how can i update the result in the same file? (inline edit)
redirect to another file, rename it back to the original.