append delimeter count for each line in text file

Hi guys, plz tell me how to achieve this
how to delete the lines in a file using sed command

awk -F"|" '{$0="delcnt"NF-1"|"$0}1' input > output && mv output input

Thanks , can you plz tell me how to achieve using sed command , bcoz as i dont have permissions to create a output file . all the edit/change operations should be performed on the input file itself.

If your sed supports -i option, you can edit the file in place:

       -i[SUFFIX], --in-place[=SUFFIX]
              edit files in place (makes backup if extension supplied)
{ rm input; awk -F"|" '{$0="delcnt"NF-1"|"$0}1'  > input; } < input

:wink:

1 Like

What a great way of handling a file!
It does works, but I am really puzzled how shell deals with file handlers, so rm deletes the file, but it somehow exists for the awk process? It would be very interesting if someone can explain

perfect.