Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Guys, I am new to UNIX world and really need help of your expertise.
I have file with each line of fixed length
eg.,DT00123 1234 FFF 56565
DT00923XX3425ZZFFFYY34281As you can see there is no fix delimeter, I want to sort the file on column which starts at char position 10 and ends at position 14
The position of the field and length of the line is fixed. So I can very well rely upon the column start and charcter position.
I was exploring the possibilities with sort but it seem it requires the delimeter to define the field.
Any script using sort, awk, sed is fine.

By default, white space is the field delimiter for sort. Why don't you choose a character for a delimiter that isn't used so the entire line is a single field and then sort on positions 10 to 14:
sort -t~ -k 1.10,1.14 mysort.txt

Fields are created with user input so I don't want to depend upon some character, because that might appear sometime.
I tried,
sort -n +0.10 -0.13 filename
and this worked fine for me. But as the manual says that this is the obsolete way. Now I want to be sure that this will cause problems to me in future.
Thanks in advance

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |