|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Hey folks,
I'm having problems with the "sort" command sorting in ASCII order. I'm working in Korn shell on a Solaris machine (Sun OS 5.8). It runs fine from the command line but doesn't work okay when I call sort from a shell script. My file has two columns and is pipe delimited and I want to sort by the first column. Here's the syntax of the command I am using. sort -o outputfile -k 1,1 -t '|' inputfile Reading around it sounds like it is locale related. I've even tried the following in my shell script and it still doesn't work. #!/bin/ksh export LC_COLLATE=C sort -o outputfile -k 1,1 -t '|' inputfile Bottom line: my sort works on the command line (sorts in ascii order) but doesn't work when called from the shell (sorts in en_US order) Please help. I'd prefer use shell scripts instead of manually typing in my commands. Thanks for your help in advance. |
|
#2
|
|||
|
|||
|
Something is funny in your envirinment.
Try the following: From the command line Code:
locale Next, issue the same command from inside your problem shell script. I think you will see some things have changed |
|
#3
|
|||
|
|||
|
Here's what I get from the command line
$ locale LANG= LC_CTYPE="C" LC_NUMERIC="C" LC_TIME="C" LC_COLLATE="C" LC_MONETARY="C" LC_MESSAGES="C" LC_ALL= The name of my shell script is "sort_test.ksh" here's what I get when I embed locale in my script: $ sort_test.ksh testdir ../dat LANG= LC_CTYPE="C" LC_NUMERIC="C" LC_TIME="C" LC_COLLATE="C" LC_MONETARY="C" LC_MESSAGES="C" LC_ALL= Thanks for your help. |
|
#4
|
|||
|
|||
|
sort responds to locale - - LC_COLLATE.
Is the file in wide characters or UTF-8 format? |
|
#5
|
|||
|
|||
|
Quote:
The file is in UTF-8 format but I got it to work after talking to a colleague in my office. I think I was having problems with the pipe delimeter. My sort now works inside a shell script by rearranging some thing and denoting the delimiter differently. Here's what finally worked: sort -d -k 1,1 -t\| -o outfile infile Thanks for replying to my earlier message |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > sort working differently in shell script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|