Help needed with date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help needed with date
# 8  
Old 03-31-2008
Yea i wish i could have done in perl. I found useful examples online. But was wondering if its possible in shell script/
# 9  
Old 03-31-2008
you can..hence the perl One-liner reference..write it in a perl sequence that you can call as a command-line call and be done with it...

# 10  
Old 03-31-2008
Ok i did this but still not working.

Code:
#today=`date '+%Y%m%d'`              # today
CUTDATE=`perl -MPOSIX -e "print strftime('%Y%m%d',localtime time -90*24*60*60)"`
cat users_log.csv | while read line
do
#while : ; do
#  read line
  datestr=`echo $line | cut -d, -f1`
  [ "$datestr" -gt "$cutdate" ] && echo $line
done > /az/web/abc.com/docs/users_log.csv
exit 0

Looks like something is wrong with my while loop. Any clue? Everytime i run my script it hangs on the screen.

Last edited by chris1234; 03-31-2008 at 11:01 AM..
# 11  
Old 03-31-2008
I'm not positive on what it is you're trying to do with your loop..I'd read your initial request as trying to peg a date value for 90 days in the past..no?

Using the examples, I would say you'd want to do the following:

Code:
my_peg_date="90" 
today_90=`perl -e '\
      $y= time - (86400 * $ARGV[0]); \
      printf "%04d%02d%02d\n", (localtime($y))[5] + 1900 ,(localtime($y))[4] + 1 ,(localtime($y))[3] ; ' ${my_peg_date} `

From there you can use that pegged value as the variable throughout the remainder of your script:

Code:
set |grep today_90

# 12  
Old 03-31-2008
Well i am trying to keep the today-90 days data and delete everything else. My cut command does not work.
# 13  
Old 03-31-2008
run this in ksh...

Code:
CUTDATE=`perl -MPOSIX -e "print strftime('%Y%m%d',localtime time -90*24*60*60)"`
awk -F, '{print $1}' users_log.csv | while read line
do
  [ "$line" -gt "$cutdate" ] && echo $line
done > /az/web/abc.com/docs/users_log.csv
exit 0

# 14  
Old 03-31-2008
Pupp thanks but unfortunately its not correct
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help needed with date compare

Hello, I have this unix script which selects rows from DB where current time is greater than expired time (column). So this will give all the records that are expired 1 day ago, 2 days ago, 3 days ago, etc.. I need help modifying in such that it should give records that are only expired 1 day... (5 Replies)
Discussion started by: jakSun8
5 Replies

2. Shell Programming and Scripting

Needed shell script to get the latest file based on date

hi i need the shell script to get the file with latest date. for example in my input folder i have files like file_20130212.txt file_20130211.txt now my output folder should have the file with latest date i.e..file_20120212.txt i want to get the latest file .. i.e is should take... (6 Replies)
Discussion started by: hemanthsaikumar
6 Replies

3. Shell Programming and Scripting

Archiving assistance needed date to month

We have year folder say in a path /opt/informat/Archive a folder 2012. And in the same folder /opt/informat/Archive we have different folders month based, like 201210, 201211, 201212, this have data for each month, ie files. Now time to time i need to move the monthly folders to the main folder... (1 Reply)
Discussion started by: raghavraok
1 Replies

4. Shell Programming and Scripting

Help needed with some date arithmetic

I have a file (main.lst) containing a list of dates in DDMMYYYY format. The dates will mostly be the same but it is possible to have multiple dates and these need not be in chronological order. I have another file containing another list of dates (holidays.lst). The task is to get the latest... (5 Replies)
Discussion started by: elixir_sinari
5 Replies

5. UNIX for Dummies Questions & Answers

date command option e Help needed please!!

Hi All, I was trying to get the date in format "Feb2" I tried option "e" giving me a padded space and getting the result as "Feb 2". Though its working fine for dates 10 to 31. Please suggest me how to get rid of this space before date. Thanks Olivia (4 Replies)
Discussion started by: Olivia
4 Replies

6. Shell Programming and Scripting

Need to zip the files date wise --urgent Help needed

Hi all, this is my first post, i need to write a script to zip the files with datewise below are the log files. -rw------- 1 root sso 85316156 May 24 22:11 core_test_smservaz_104_104_1243217459_8896 -rw------- 1 root sso 90413304 May 25 22:12 core_test_smservaz_104_104_1243303895_20912... (4 Replies)
Discussion started by: lcschandu
4 Replies

7. Shell Programming and Scripting

Help needed-calculate previous date

Hi Friends, Need a command/script in unix which calculates previous date from current date. For ex: If current date= 01 Jan 2008, then output =31 Dec 2007 If current_date =01 Aug 2008 , then output= 31 July 2008 Please advice Regards, Suresh (3 Replies)
Discussion started by: sureshg_sampat
3 Replies

8. Shell Programming and Scripting

Help Needed in Date Condition !!

I am writing an shell script , which reads a file with contents Example :: (( This Format is yyyy-MM-DD)) 2008-05-16 2008-05-17 2008-05-18 2008-05-19 2008-05-20 2008-05-21 when i run the shell script it has to check the current date and compare it with the todays date and give me... (24 Replies)
Discussion started by: ranga27
24 Replies

9. Shell Programming and Scripting

help needed in date format

i need to grep date in the format year-month-day,,,,,,, actually i need to grep those dates other than current date.......... can anyone help me in this...........i need a format of date which would grep previous date except current date (1 Reply)
Discussion started by: ali560045
1 Replies

10. Shell Programming and Scripting

Help needed on Date command

Hi, I am facing one problem with date command.Actually I want to use this command to get the last month,not the current month..OK,I can do current month - 1 and give special condition for january,But this time i need last month as strings like January,februaury,march etc... There is option... (5 Replies)
Discussion started by: nikunj
5 Replies
Login or Register to Ask a Question