Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Apr 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sorting part of a file and retaining the other text using batch script

    Hello All,

    I have a file(.txt) which I want to sort using the batch file.
    While sorting, only a part of file I wanted to sort, the rest I wanted to retain.

    Ex:
    This is for test
    //Testing Done
    {
    //"Places in US": brief,
    "New york": testing,
    "Chicago": testing,
    "LA": testing
    };
    //"New Testing"
    This is the End of the File
    So, from the above file contents, only the line with places in "double quotes" I wanted to sort except the commented(//) brief part.
    So, after sorting, it should be:
    This is for test
    //Testing Done
    {
    //"Places in US": brief,
    "Chicago": testing,
    "LA": testing
    "New york": testing,
    };
    //"New Testing"
    This is the End of the File
    I tried
    Code:
     findstr /r /i /c:":" test.txt | sort > sorted_test.txt
    Which was not fruitful.

    So, Any help appreciated.
    Thanks in advance.

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Lounger
    Join Date
    Feb 2012
    Posts
    48
    Thanks
    2
    Thanked 5 Times in 4 Posts
    The resident batch file guru monitors the "Windows Programming" section of the forum -- not certain he would see your post here. But even if he did, this is a tall order.

    I would make do with a text editor. The manual procedure would be to open the file in a text editor, select the block of lines to be sorted, and choose Sort via menu or keyboard shortcut.

    One step up in automation would be a macro. A Notepad++ macro might go like this:
    Find //"Places in US"
    Down
    Home
    Edit/"Begin/End Select"
    Find }:
    Home
    Edit/"Begin/End Select"
    Edit/Line Operations/Sort-Ascending
    Ctrl+Home

    A step up from that might be to initiate the process of opening, modifying, saving and closing the file by means of a SendTo menu item or drag-and-drop target. For this I would use NoteTab.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •