UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old October 13th, 2004, 10:55 AM
robblerobble robblerobble is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 robblerobble User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool sort working differently in shell script

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.

Reply With Quote
  #2  
Old October 13th, 2004, 12:35 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
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

Reply With Quote
  #3  
Old October 13th, 2004, 12:44 PM
robblerobble robblerobble is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 robblerobble User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old October 13th, 2004, 12:48 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
sort responds to locale - - LC_COLLATE.

Is the file in wide characters or UTF-8 format?

Reply With Quote
  #5  
Old October 13th, 2004, 01:29 PM
robblerobble robblerobble is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 robblerobble User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Figured it out!

Quote:
Originally Posted by jim mcnamara
sort responds to locale - - LC_COLLATE.

Is the file in wide characters or UTF-8 format?


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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > sort working differently in shell script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway