asked 146k views
3 votes
Write a shell script that will take an input file and remove

identical lines (or duplicate lines from the file) (ubuntu)

asked
User Meldim
by
8.1k points

1 Answer

7 votes

Final answer:

To remove identical lines or duplicate lines from a file using a shell script in Ubuntu, you can use the sort and uniq commands.

Step-by-step explanation:

To remove identical lines or duplicate lines from a file using a shell script in Ubuntu, you can use the following steps:

  1. First, you need to sort the file using the sort command. This will group identical lines together.
  2. Next, you can use the uniq command with the u option to remove duplicate lines and keep only unique lines.
  3. Finally, you can redirect the output to a new file to save the modified version of the input file.

An example of a shell script to accomplish this:

sort input.txt | uniq -u > output.txt-

answered
User Rasheema
by
8.3k points

Related questions