Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8669629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:31:24+00:00 2026-06-12T18:31:24+00:00

Say I have a file like: apple pear lemon lemon pear orange lemon How

  • 0

Say I have a file like:

apple
pear
lemon
lemon
pear
orange
lemon

How do I make it so that I only keep the unique lines, so I get:

apple
pear
lemon
orange

I can either modify the original file or create a new one.

I’m thinking there’s a way to scan the original file a line at a time, check whether or not the line exists in the new file, and then append if it doesn’t. I’m not dealing with really large files here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:31:25+00:00Added an answer on June 12, 2026 at 6:31 pm
    @echo off
    setlocal disabledelayedexpansion
    set "prev="
    for /f "delims=" %%F in ('sort uniqinput.txt') do (
      set "curr=%%F"
      setlocal enabledelayedexpansion
      if "!prev!" neq "!curr!" echo !curr!
      endlocal
      set "prev=%%F"
    )
    

    What it does: sorts the input first, and then goes though it sequentially and outputs only if current line is different to previous one. It could have been even simpler if not for need to handle special characters (that’s why those setlocal/endlocal are for).
    It just echoes lines to stdout, if you want to write to file do (assuming you named your batch myUniq.bat) myUniq >>output.txt

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have something like this in my web.xml file. <filter name=foo>
Let's say I have an empty XML file like so: <root></root> And I want
Lets say I have a few utility functions in file tests/utils/functions.js. I would like
If I have a a textfile say file.txt and it contains random words like:
So say you have a file that is written in XML or soe other
Let's say I have a file that's Modified in master Modified in a feature
Say I have a text file like so: apples pencils juice apricots John Doe
Let's say I have a file like this: <outer> <inner> <nodex attr=value1>text</attr> <nodex attr=value2>text</attr>
I have a human dictionary file that looks like this in eng.dic (image that
Let’s say we have an array like that array(2) { [2012]=> array(2) { [0]=>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.