2

I'm running the following command to add line numbers:

perl -pe '$_ = "$. $_"'

I can append the results to a file with:

cat test.txt | perl -pe '$_ = "$. $_"' >> test.txt

But if I try to replace the current contents the file ends up blank:

cat test.txt | perl -pe '$_ = "$. $_"' > test.txt

Why is this?

  • 1
    for in place editing, just use perl -i -pe '$_ = "$. $_"' test.txt... also there is a command nl for numbering purposes – Sundeep Jul 26 '17 at 14:09

0 Answers0