Try just having your first line in your input file have a <space> as the 1st character on the line and sort with the command:
Specifying a non-space field separator should make the leading space significant.
If you don't want a visible space at the start of the first line, make the first two characters in the file be a <space> character followed a <backspace> character.
Thanks for the reminder. I actually had " \bHost = xxx, topdir=ddd etc"
but without the -t the sort interprets the line, so that it saves it as Host=xxx ....
In 20 minutes, I will do the test as you suggested. The only change I have to do is test the sort parameters.
---------- Post updated at 07:23 PM ---------- Previous update was at 07:08 PM ----------
This is the top part of my file. Notice the !!^HHost= (^H=Backspace)
Is the sort program too smart. I used '!' to collate low so that my title line stayed first. I tried it with ' ' when piped to the sort as ... | sort -t '|' > x
Last edited by Scrutinizer; 03-01-2014 at 09:23 PM..
Reason: quote tags to code tags
With the data shown in message #4 in this thread in a file named input.txt, I get the following data saved in the file named x from the command:
The order of lines in the output is the same when the line containing Host= is:
The system I'm using for this test is Mac OS X 10.7.5 running on a MacBook Pro laptop. This is the output I would expect for any sort utility conforming to the POSIX standards.
Note that the <space><backspace> before: /home/leslie/Development/scandirFeb23 in that line doesn't matter unless you're sorting on that field with something like:
In the input sample you provided the header line was:
What I was saying was that the <space><backspace> (marked in red above) doesn't make any difference unless you're sorting on the 4th field instead of the 1st field. I didn't understand why those characters were present in your sample input.
Quote:
Originally Posted by lsatenstein
I was trying to sort by the first column. And for all that I tried,
the Host=Fedora .... was placed somewhere in the middle of the output file.
If I sorted on fields 2,3,4, the sort yields what I require.
If I did not specify a "-b" with the sort, it should assume the leading blanks are part of the field and should not be skipped over
.
Thank for your patience and help.
Yes. You are correct. If sort on your system behaved as specified by the standards, the -t option should not be needed in this case. I suggested using the -t option because of disedorgue's comment in message #4 in this thread:
Quote:
There was some version of "gnu sort" with a bug of '-b' option was enabled by default.
Since there is an interaction between the -b and -t options (although it isn't as clearly specified in the Linux sort(1) man page as it is in the POSIX sort utility man page), I thought that if your version of sort did have this bug, using the -t option might provide a work around.
I guess I was bleary eyed last night when I indicated that everything was ok, but ....
Sorting for columns 2 through 4 works fine.
How do I make the sort work for column 1?
Do I need to add a leading | symbol before column 1?
Please refer to the list I posted yesterday, a few messages back.
Is the problem me or the sort's limitations?
I assume that you're referring to the following which is from message #8 in this thread:
Quote:
This is the top part of my file. Notice the !!^HHost= (^H=Backspace)
Note the two sections marked in red. Your description of the sample input shows !!\bHost= (where \b is the backspace character) but the data in the file shows !! Host= (with a space instead of a backspace). Note that if that file did contain a backspace before Host= instead of a space, then sorting that file using the command:
would produce output exactly matching the input you showed us.
Please upload the exact sample input_file you're using, show us the exact command line you're using to sort that file, the exact output you're getting from that command line, and the exact output you're trying to get.
Unless you want exclamation points in the header in your output, please use a space followed by a backspace as the 1st two characters on the header line instead of two exclamation points followed by a space.
Thank you for your posting. I too, discovered the -f option this evening and then I read your response when I came to post my finding.
The data you see above had many many iterations to try to get it to work to my requirements. My original output was produced in the printf statement beginning printf( " \bHOST=%s... ..); (one space and one backspace before the H)
From what I understood, the sort command, if issued against x.raw, the file to be sorted, with the following comand line
should keep the first line invariant, but it does not. It appears to require the -f to almost meet my needs.
The manual states that the -f was to fold upper to lower case together to lowercase.
I really was after the ascii collating sequence. Ergo With the -f option, Date1 and Date2 are in the wrong place, but the first line is maintained as was desired.
Is it possible that the sort is missing an option to "just sort a column", purely respecting the ascii contents of the field?
If the above answer is no, then if it was up to me, I would request a -e parameter (when used with -t ). It would be used to stop interpretation of leading blanks and non-alpha characters.
In closing, thanks for your help and for the others in the forum who responded.
Last edited by Scrutinizer; 03-03-2014 at 01:17 AM..
Reason: code tags
Hello,
I am looking to automate a task - which is updating an existing access control instruction of a server and making sure that the attributes defined in the instruction is in sorted order. The instructions will be of a specific syntax.
For example lets assume below listed is one of an... (6 Replies)
Hi all,
I have a file with 3 columns separated by space. Each column has a heading. I want to sort according to the values in the 2nd column (ascending order).
Ex.
Name rank direction
goory 0.05 --+
laby 0.0006 ---
namy 0.31 -+-
....etc.
Output should be
Name rank direction
laby... (3 Replies)
I am in need of keeping a title of a report and removing duplicates from a file like the one below. I will be using the `uniq –u` command for the removal of duplicate lines (let me know if there is a better way rather than the command `uniq`) but I need to keep the title (first 9 lines) of the... (2 Replies)
HI all
i have a text file file1 like this
004002004545454000001
041002004545222000002
006003008751525000003
007003008751352000004
006003008751142000005
004001005745745000006
i want to sort the file according to position 1-5 and secondary sort by
the last position of file 16-21... (4 Replies)
So, I have a file that has some duplicate lines. The file has a header line that I would like to keep at the top.
I could do this by extracting the header from the file, 'sort -u' the remaining lines, and recombine them. But they are quite big, so if there is a way to do it with a single... (1 Reply)
Hello,
I have a text file that I need to sort the lines by date
record=5,French 9,2008-09-02T08:55:00,2008-09-02T10:00:00,2
record=79,Entrepreneurship 30,2008-09-17T11:00:00,2008-09-17T12:00:00,2
record=6,Computer Science 20,2008-09-02T09:55:00,2008-09-02T10:50:00,1... (5 Replies)
Hi,
I want to delete a line in a file that contains a string. I tried:
grep -v "mystring" Myfile > Myfile
But this makes the Myfile empty. I read that I need to do something like:
grep -v "mystring" Myfile > Myfile.new
rm Myfile
mv Myfile.new Myfile
Is there a way to avoid creating a... (2 Replies)
infile:
z y x
c b a
desired output:
x y z
a b c
I don't want to sort the lines into this:
a b c
x y z
nor this:
c b a
z y x
The number of fields per line and number of lines is indeterminate. The field separator is always a space.
Thanks for the use of your collective brains.... (11 Replies)