Sponsored Content
Top Forums Shell Programming and Scripting Converting a date to friday date and finding Min/Max date Post 302678389 by Chirel on Friday 27th of July 2012 06:37:05 PM
Old 07-27-2012
Hi,

another way

inputfile
Code:
20120624
20120625
20120626
20120627
20120628
20120629
20120630
20120701
20120702
20120703
20120704
20120705
20120706
20120707
20120708
20120709
20120710
20120711
20120712
20120713
20120714
20120715
20120716
20120717
20120718
20120719
20120720
20120721
20120722

The code
Code:
awk '{oneday=24*60*60; ctm=mktime(substr($1,1,4) " " substr($1,5,2) " " substr($1,7,2) " 00 00 00"); dow=strftime("%u",ctm); toadd=(dow<=5?5-dow:12-dow)*oneday; print strftime("%Y%m%d",ctm+toadd);}' infile

Output :
Code:
20120629
20120629
20120629
20120629
20120629
20120629
20120706
20120706
20120706
20120706
20120706
20120706
20120706
20120713
20120713
20120713
20120713
20120713
20120713
20120713
20120720
20120720
20120720
20120720
20120720
20120720
20120720
20120727
20120727

 

10 More Discussions You Might Find Interesting

1. HP-UX

a simple way of converting a date in seconds to normal date

Hi all! I'm working on a HPUX system, and I was wondering if there is a simple way to convert a date from seconds (since 1970) to a normal date. Thanks (2 Replies)
Discussion started by: travian
2 Replies

2. Shell Programming and Scripting

Get the date of monday when running from Friday to next Thursday

Hi, I have a requirement where I want to get the date of monday when I am running the script from previous Friday to the following Thursday. For example: When ever I run the script between 19thFeb2010(Friday) to 25th Feb 2010(Thursday), I should get the date of 22nd Feb 2010 in the format of... (5 Replies)
Discussion started by: fasiazhar_411
5 Replies

3. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

4. Shell Programming and Scripting

finding the previous day date and creating a file with date

Hi guys, I had a scenario... 1. I had to get the previous days date in yyyymmdd format 2. i had to create a file with Date inthe format yyyymmdd.txt format both are different thanks guys in advance.. (4 Replies)
Discussion started by: apple2685
4 Replies

5. Shell Programming and Scripting

To get max/min Date/Timestamp from a file

I want to get maximum/minimum date/timestamp from a data file ? Sample Input File ============= rec#,order_dt,ext_ts 1,2010-12-01,2010-12-01 17:55:23.222222 2,2011-11-05,2010-12-01 19:55:23.222222 3,2009-10-01,2010-12-01 18:55:23.222222 for above file Maximum Order_dt = 2011-11-05... (5 Replies)
Discussion started by: vikanna
5 Replies

6. Shell Programming and Scripting

finding date numeral from file and check the validity of date format

hi there I have file names in different format as below triss_20111117_fxcb.csv triss_fxcb_20111117.csv xpnl_hypo_reu_miplvdone_11172011.csv xpnl_hypo_reu_miplvdone_11-17-2011.csv xpnl_hypo_reu_miplvdone_20111117.csv xpnl_hypo_reu_miplvdone_20111117xfb.csv... (10 Replies)
Discussion started by: manas_ranjan
10 Replies

7. Red Hat

How to find/display out last Friday's date of the month?

Hello, Can you please help me find/display out last Friday's date of the month using command in Unix/Linux (3 Replies)
Discussion started by: sunnysthakur
3 Replies

8. Shell Programming and Scripting

Converting String Date into UNIX Date

Hi, I have a string date to my unix script(sun solaris). I wanted to convert it into unix date so that I can use it in a conditional statement. Please see below: MyTest.sh -s 2018-05-09 suppdt=$1 # string date passed via arguement as 2018-04-09 curryr=`date '+%Y'` nextyr=`expr... (2 Replies)
Discussion started by: Saanvi1
2 Replies

9. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

10. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies
tapset::string(3stap)													     tapset::string(3stap)

NAME
tapset::string - systemtap string tapset DESCRIPTION
strlen Returns the length of a string See function::strlen(3stap) for details. substr Returns a substring See function::substr(3stap) for details. stringat Returns the char at a given position in the string See function::stringat(3stap) for details. isinstr Returns whether a string is a substring of another string See function::isinstr(3stap) for details. text_str Escape any non-printable chars in a string See function::text_str(3stap) for details. text_strn Escape any non-printable chars in a string See function::text_strn(3stap) for details. - strtol Convert a string to a long See function::-strtol(3stap) for details. isdigit Checks for a digit See function::isdigit(3stap) for details. SEE ALSO
function::strlen(3stap), function::substr(3stap), function::stringat(3stap), function::isinstr(3stap), function::text_str(3stap), function::text_strn(3stap), function::-(3stap), function::strtol(3stap), function::isdigit(3stap), stap(1), stapprobes(3stap) IBM
--- tapset::string(3stap)
All times are GMT -4. The time now is 07:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy