473,399 Members | 2,146 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,399 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 2206
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.