0

I have a text file which contains thousands of lines with same links. I want append the line number at the end of each line. For example;

https://example.com/
https://example.com/

these links would become:

https://example.com/1
https://example.com/2

and so on. I tried using the following code:

sed -n 'p;=' file | paste -d":" - -

However, it printed all the lines of the text file and the line number in the terminal in the following manner:

https://example.com/:1
https://example.com/:2
2
  • Are you open to a perl one-liner solution?
    – Toto
    Commented Mar 31, 2023 at 9:51
  • @Toto yes, i'm open to a perl one-liner solution. Commented Mar 31, 2023 at 11:51

1 Answer 1

1

This perl one-liner does the job:

perl -i -ape 's/$/$./' inputfile

Where $ stands for end of line and $. is the current line number.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .