473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Regarding date command unix option %e

I have a log file with contents within the file having the date format as follows on some lines:
Sep 5, 2010

Now, I am trying to run a script to parse through the log file. Since I want to grep all the entries for today's date, I use the date command:
date '+%b %e, %Y'

The problem is, %e should return "Sep(doublespace)5, 2010" (notice double space after 'Sep' - I have not tried this as today is 30th September but just assumuing based on the date manual page which says the day will be preceeded by white space), thus it is not able to grep the exact string I want which is "Sep(singlespace)5, 2010" (notice single space after 5). I thought this should be easy with some experts out there.

Also, %d will not work since it preceeds the single digit days with a 0 (zero) whereas my log file does not have a preceeding 0 (zero) for single digit days.

Also, would like to know if I can get rid of this by doing a sed command - would like to avoid it though. Please advice.
Sep 30 '10 #1
1 2202
ashitpro
542 Expert 512MB
I tried few commands.

This is my a.txt
Expand|Select|Wrap|Line Numbers
  1. Oct 1, 2010
  2. Oct 30, 2010
  3. Oct  1, 2010
  4. Oct  30, 2010
  5.  
So, my approach would be, don't rely on spaces inside the file.
Separate month, day and year using date command and then apply the appropriate regex to search the pattern.

In my case, I have done.

Expand|Select|Wrap|Line Numbers
  1. mon=`date '+%b'`
  2. day=`date '+%e'`
  3. yr=`date '+%Y'`
  4.  
  5. grep -e "$mon.*$day.*$yr" a.txt
  6.  
It should produce,
Expand|Select|Wrap|Line Numbers
  1. Oct 1, 2010
  2. Oct  1, 2010
  3.  
I have put the simplest regex for grep, I don't know the consequences with your file.
So change it accordingly.
Oct 1 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Christopher Wood | last post by:
Greetings all, A quick query: as all sorts of stuff can be defined in a .pythonrc.py file or similar and called at python startup using the PYTHONSTARTUP environment variable, it's very useful...
0
by: Nitin Gaur | last post by:
Hi, I am developing an application using Visual Studio .NET in C++. I am using following command to automate the debugging of this executable: devenv -command Debug.StepInto myProg.cpp...
0
by: sumeet | last post by:
how do i convert a yyyymmdd format to yyyy,mm,dd format. also i want to know how do i get the number of days between two dates which r in the format yyyymmdd. how to convert date into unix time...
0
by: Dean N. Williams | last post by:
Dear Python and Mac Community, I have just successfully built gcc version 4.1.0 for my Mac OS X 10.4.6. gcc -v Using built-in specs. Target: powerpc-apple-darwin8.6.0 Configured with:...
1
by: SenthilVel | last post by:
Hi I am in the Process of conversion of my existing 1.1 Dotnet Code to 2.0 framework. for each project when i compile in VS2005 , i get this error\warning: Use command line option...
4
by: SenthilVel | last post by:
Hi I am in the Process of conversion of my existing 1.1 Dotnet Code to 2.0 framework. for each project when i compile in VS2005 , i get this error\warning: Use command line option...
11
by: Michele Simionato | last post by:
The subject says it all, I would like a script to act differently when called as $ python script.py and when called as $ python -i script.py. I looked at the sys module but I don't see a way to...
6
by: marc | last post by:
hi im trying to convert Date() into a unix timestamp so i can stick the result into a mysql db, please help!
5
by: Rajesh | last post by:
Hi, The '-I<path>' option adds the path to the list of directories that contains modules that can be included in a script. I can use it as "#!/ usr/bin/perl -I<path_to_my_modules>" thereby not...
1
by: kanni04 | last post by:
While doing the setup of the project we have to attach the fine dotnetfx.exe file. while installing that it will giving the error box with "COMMAND LINE OPTION SYNTAX ERROR. TYPE COMAND /? FOR ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.