read line

Hello,

I want to read a file line by line and every time i find a sting that starts with:

"USER      PID     PPID  %CPU  %MEM  STARTED        TIME   VSZ   RSS COMMAND"

add a sequential number.

i.e.

"1   USER      PID     PPID  %CPU  %MEM  STARTED        TIME   VSZ   RSS COMMAND"
"2  USER      PID     PPID  %CPU  %MEM  STARTED        TIME   VSZ   RSS COMMAND"
"3  USER      PID     PPID  %CPU  %MEM  STARTED        TIME   VSZ   RSS COMMAND"......

the output should be on a second file (ft_tmp.log)

I did:

i=1
add=$i
while read line;
do
    `sed -n /USER/,/COMMAND/p | sed  "s/^/$add /g" > ft_tmp.log`
    let add=add+1
    let i=i+1
done

but all the lines get the same value (1)...

HELP......

grep 'USER PID PPID %CPU %MEM STARTED TIME VSZ RSS COMMAND' yourfile| cat -n

I dont understand how to use the input you provided...

replace yourfile with the name of the file you are trying to read and add line numbers to

My interpretation of your post. Would help to see before and after samples and to mention what environment you have.
Incrementing $add may be different in your shell.

add=1
while read line
do
    prefix=`echo "${line}"|cut -c1-4`
    if [ "${prefix}""X" = "USER""X" ]
    then
          echo "${add} ${line}"
    else
          echo "${line}"
    fi
    add=`expr ${add} + 1`
done < filename >ft_tmp.log

I can see there being layout problems if this is the output from "ps" appended to a file because it will displace the heading across the screen.