Below is a part of script which gives proper output when run manually but gives incorrect output when run using cron:

sort < file1.out | uniq -ic |sort -nr> file2.out

When run on the command line, this gives a count where lines are grouped ignoring case, such as:

73 /universal/webselfservice/pdf/r60.pdf

When running through cron, the counts are split when case varies, for example:

47 /universal/webselfservice/pdf/r60.pdf
26 /universal/webselfservice/pdf/R60.pdf

How can I get the cron output to match the command line behavior?

  • could be because you need to give the explicit path to the input and output files for the cron job. or try specifying sort -f
    – gogoud
    Dec 2, 2015 at 16:08

1 Answer 1


The locale used under cron is different to that in your interactive environment. One has case case-insensitive collation, and the other does not.

This means that interactively, the first sort puts /universal/webselfservice/pdf/r60.pdf and /universal/webselfservice/pdf/R60.pdf adjacent, so uniq -i can combine them. But in the locale used by cron, they are not adjacent, and get counted separately.

There two simple means to get what you want:

  1. specify your case-insensitive locale as an environment variable in your crontab file, or
  2. add -f (or --ignore-case) flag to the first sort.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.