LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-10-2003, 04:48 AM   #1
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
getting last locale's abbreviated month name through bash scripting


Is it possible to get the last locale's abbreviated month name using bash scripting? I'd like to archive following:
Code:
gunzip --stdout /var/log/mail.*.gz | grep "^Apr" | sort -g | /usr/local/sbin/reports/mail/pflogsumm.pl
Apr should be replaced with the last month!

Is it possible using bash scripting to do that? I mean it's pretty easy in perl, but I'd like not to wrapper a perl script around if not required!

Last edited by markus1982; 05-10-2003 at 04:53 AM.
 
Old 05-10-2003, 08:08 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
(Assuming you use Debian and want the German language)
First you need to make sure the "locales" package is installed:

apt-get install locales

if it is already installed, reconfigure it:

dpkg-reconfigure locales

In either case, the debconf screen appears, where you can select locale files to be generated. Choose at for example "de_DE ISO-8859-1" and leave the default locale to "C" as suggested by debconf.

To test, enter (in bash):

LANG=de_DE date

If it works you can use it in the command line as follows:
Code:
gunzip ....  | grep "`LANG=de_DE date +%b`" | sort -g | ....
Or, to use german by default in the current shell, you can "export LANG=de_DE" first and then just use:
Code:
gunzip ....  | grep "`date +%b`" | sort -g | ....
If I get your question right, you would like to have the previous month. Like we are in may right now, and you'd like to grep for april. To do that, use:
Code:
LANG=de_DE date -d '1 month ago' +%b
Hope this helps. For more information see "info date" (not "man date", as the man page does not explain the -d '1 month ago' - like options.

Last edited by Hko; 05-10-2003 at 08:20 AM.
 
Old 05-10-2003, 08:31 AM   #3
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Original Poster
Rep: Reputation: 46
Quote:
Hope this helps. For more information see "info date" (not "man date", as the man page does not explain the -d '1 month ago' - like options.
I should really have checked the info pages. Didn't think about that at the time I did it.

Thanks alot for reminding me to the importance of the info pages. I was just looking for date -d '1 month ago' +%b :-)


Now the script works just perfect:
Code:
gunzip --stdout /var/log/mail.*.gz | grep "^`date -d '1 month ago' +%b`" | sort -g | /usr/local/sbin/reports/mail/pflogsumm.pl
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
transform month number to month name in php ALInux Programming 1 11-09-2005 10:45 AM
Converting number to locale's abbreviated month name tsilok Linux - Newbie 4 10-25-2005 05:18 PM
bash scripting fnoyan Programming 1 01-18-2005 07:35 AM
bash month variable johniccp Linux - Newbie 1 12-06-2004 01:41 PM
Starting day of month, month length chrisk5527 Programming 2 03-03-2004 04:03 PM


All times are GMT -5. The time now is 04:09 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration