The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
from - to delimiter bighippo Shell Programming and Scripting 6 03-12-2008 11:47 PM
awk,nawk,sed, delimiter |~| knijjar Shell Programming and Scripting 7 02-18-2008 11:38 PM
replace the last delimiter jisha Shell Programming and Scripting 4 01-28-2008 03:26 AM
Cut Number which appear before a delimiter Raynon Shell Programming and Scripting 2 09-30-2007 05:40 PM
\r as delimiter in cut shweta_d Shell Programming and Scripting 5 06-07-2007 06:18 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-31-2007
Registered User
 

Join Date: Apr 2007
Posts: 32
Cut date using y hat as delimiter

QUESTION: How can I cut out the date from just the first line and reformat it to 31-Jul-2007? I'll restate the question at the bottom again...

DESCRIPTION: I need to cut a date out of a file - an example of the date's format in the file is 2007-07-31. It's in the 5th field and is separated by y with an accent over it, so I need to print the value of that delimiter. There are 10's of thousands of lines in the file, but I only need to scan the first line for this date. So far I have the following, and while it at least gives me some kind of output, it's obviously not what I need (actually, it's returning every line in the file - I know this because it tried to do that before I copied it to a 'test' file and deleted all the other lines but the first):

DATE=`cut -d 'printf "\375"' -f5 < file.test`

echo $DATE returns the whole line (or really, the whole file), something like this (the y's have a forward accent over them):

18y835y000000ySy2007-06-13y09:40:38y

QUESTION: how can I cut out the date from just the first line and reformat it to 31-Jul-2007?

I found part of the answer:

cat tlog.test | cut -f5 -d`printf "\375"` | tail -1

Produces (I mentioned the wrong date above):

2007-06-13

Now how do I reformat it to 13-Jun-2007 without using a hard-coded date?

Last edited by tekster757; 07-31-2007 at 09:24 AM. Reason: I found part of the answer
Reply With Quote
Forum Sponsor
  #2  
Old 07-31-2007
Shell_Life's Avatar
Registered User
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Code:
mVar='2007-06-11'
mYear=`echo $mVar | cut -d'-' -f1`
mMth=`echo $mVar | cut -d'-' -f2`
mDay=`echo $mVar | cut -d'-' -f3`
mAllMths='Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'
mMthOut=`echo ${mAllMths} | cut -d' ' -f${mMth}`
echo ${mDay}'-'${mMthOut}'-'${mYear}
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0