retain Line numbers.. in Vi .. OR .. A SHELL SCRIPT

Hello everybody !

GOT SOMETHING INTERESTING...

I am trying to retain line number for a text document.. usually we get line numbers in VI using :set nu , but I want to permanently store them. It's a 4000 lines of text and I want grep/search it for a list of words/fields stored in a different file. what I was asked to do was a manual task. but I thought of writing a script. The script will return the whole line including the line number just embeded. So, I can directly point out where a specific word has been referred.

here is the script I got till now.
#!/bin/ksh
ctr=0
IFS="\n"
for lines in `cat plsql`
do
((ctr=${ctr}+1))
linenum="${ctr}"
if [[ ${ctr} -lt 10 ]]
then
linenum="000${ctr}"
else
if [[ ${ctr} -lt 100 ]]
then
linenum="00${ctr}"
else
if [[ ${ctr} -lt 1000 ]]
then
linenum="0${ctr}"
fi
fi
fi
echo "${linenum} ${lines}" >> plsqllin
done

Thanks

You are doing way too much work for a very simple task! From what I get of your question, you want to grep for a particular word/s in the file and get the line number where the word is. Just do this:

grep -n "pattern-to-grep" filename

The -n prefixes the output with the number of the line where the pattern is present.

Cheers!

wow.. It was so simple.. It never crossed my mind.. thanks once again