Results 1 to 4 of 4

Thread: Unix Sort

  1. #1
    Join Date
    Feb 2014
    Posts
    3

    Unanswered: Unix Sort

    Hi,
    Im developing a utility, and one of the challenge is to sort data in the files in a folder, which has more than 10 text files.
    It is doing the sorting properly, but one particular file alone it sorts the data but leaves an empty line at the beginning.
    How can we avoid this using Sort option?
    for eg: the data before sort would be like this.
    <data>
    cat
    fox
    dog

    After the sort it would be like this(leaving one space on the first line and starts from the second)
    <data>

    cat
    dog
    fox

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    There is a blank line at the end of the file. Remove it.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    sort does not have a sieve or filter function.
    Write a script to remove any unwanted lines in the input file.
    Code:
    grep -v "\^ " inputfile |sort
    Will remove all records with a space in column 1.
    If the file has line feeds without any data then:
    Code:
    #/bin/bash
    while read line
    do
    if [ ${#line} -ne 0 ]
    then
    echo "$line"
    fi
    done

  4. #4
    Join Date
    Feb 2014
    Posts
    3
    Thank You All.
    kitaman's suggestion worked for me.
    Pat Phelan: Yeah there was indeed a blank line.

    Thanks Once again.

Posting Permissions

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