How to edit txt file by shell script?

What I want to do is just delete some lines from a text file, I know it's easy using copy and redirect function, but what I have to do is edit this file (delete the lines) directly, as new lines may be added to the text file during this period. Can AIX do this ?

# cat text

1:line1
2:line2
3:line3
4:line4

# xxxx.sh text <---- Is it possible?

#cat text

1:line1
2:line4
3:new line added by other processes

I think you can try it out with grep -v option ,

thanks, :slight_smile:

To my understanding it is not.As what you want is, you wish to open a file in write mode by two different processes

  1. By your logging process.
  2. Another by your deletion process.

If say logging processes release file lock at some interval of time you can go in for deletion-
with something like

sed -e 'n,n+1d' file > newfile
mv newfile file

using "sed" or "awk" command can do that