Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Parsing a column of text file - best practices

UNIX for Beginners Questions & Answers


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-19-2017
SIMMS7400 SIMMS7400 is online now
Registered User
 
Join Date: Apr 2016
Last Activity: 21 October 2017, 6:08 AM EDT
Posts: 128
Thanks: 28
Thanked 3 Times in 3 Posts
Parsing a column of text file - best practices

HI Folks -

I hope all is well! I have a business process where I manage a text file of substitution variables and their values for a target system. After updating, I run a script to push the changes to the target system.

However, I'm trying to develop a method to be able to automatically advance values without manual intervention. Obviously there may be some exceptions I need to handle in an automated fashion which is fine.

So, the advancement I need to do is week, month and year, based on what subvar it is...

Here is a portion of a sample file :


Code:
CurrentWeek,02/04/17
CurrentWeekq,"02/04/17"
CurrentPeriod,FEB17
CurrenttPeriodq,"FEB17"
1PeriodPrior,JAN17
1PeriodPriorq,"JAN17"
2PeriodPrior,DEC17
2PeriorPriorq,"DEC17"
CurrentPlanYear,FY 2017
CurrentPlanYearq,"FY 2017"

So, i'm trying to understand the best way to advance. The process runs EVERY Saturday, so as you know, the subvars pertaining to the day/week (xx/xx/xx) will always roll forward, but month and year wont until a new month or new year changes...

So this Saturday, CurrentWeek would roll forward to 2/11/17..All others would remain the same.

However on march forth, all week and MONTH subvars will advance. Years wont advance until we advance for Jan 2018.

Just looking for the best way.

Thank you!
Sponsored Links
    #2  
Old Unix and Linux 05-19-2017
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 21 October 2017, 4:43 AM EDT
Location: Amsterdam
Posts: 11,573
Thanks: 510
Thanked 3,355 Times in 2,959 Posts
With GNU date, you can try:

Code:
date +'CurrentWeek,%m/%d/%y
CurrentWeekq,"%m/%d/%y"
CurrentPeriod,%^b%y
CurrentPeriodq,"%^b%y"'
date +'1PeriodPrior,%^b%y
1PeriodPriorq,"%^b%y"' --date='1 month ago'
date +'2PeriodPrior,%^b%y
2PeriodPriorq,"%^b%y"' --date='2 months ago'
date +'CurrentPlanYear,FY %Y
CurrentPlanYearq,"FY %Y"'

Sponsored Links
    #3  
Old Unix and Linux 05-19-2017
SIMMS7400 SIMMS7400 is online now
Registered User
 
Join Date: Apr 2016
Last Activity: 21 October 2017, 6:08 AM EDT
Posts: 128
Thanks: 28
Thanked 3 Times in 3 Posts
Thank you for that reply! Unforunately, CurrentWeek isn't actually the current week. Right now, its 02/04/17.

That's where I'm struggling.
    #4  
Old Unix and Linux 05-20-2017
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 October 2017, 6:21 AM EDT
Location: Aachen, Germany
Posts: 11,480
Thanks: 310
Thanked 3,561 Times in 3,276 Posts
And what does "02/04/17" represent? Would be valuable to know if we want to automate anything.
Sponsored Links
    #5  
Old Unix and Linux 05-20-2017
SIMMS7400 SIMMS7400 is online now
Registered User
 
Join Date: Apr 2016
Last Activity: 21 October 2017, 6:08 AM EDT
Posts: 128
Thanks: 28
Thanked 3 Times in 3 Posts
My apologies, this is a new requirement for me and the data provided was outdated. Therefore, CurrentWeek actually means current week.

Since these are rolled forward every Saturday, CurrentWeek is 5/20/17.

As it looks, I'm going to try Scrutinzer's solution, but please suggest another option if there is a better way.

Thank you!
Sponsored Links
    #6  
Old Unix and Linux 05-20-2017
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 21 October 2017, 2:19 AM EDT
Location: San Jose, CA, USA
Posts: 10,553
Thanks: 554
Thanked 3,696 Times in 3,153 Posts
Quote:
Originally Posted by SIMMS7400 View Post
My apologies, this is a new requirement for me and the data provided was outdated. Therefore, CurrentWeek actually means current week.

Since these are rolled forward every Saturday, CurrentWeek is 5/20/17.

As it looks, I'm going to try Scrutinzer's solution, but please suggest another option if there is a better way.

Thank you!
It's not just outdated, it's also inconsistent:

Code:
CurrentWeek,02/04/17
CurrentWeekq,"02/04/17"
CurrentPeriod,FEB17
CurrenttPeriodq,"FEB17"
1PeriodPrior,JAN17
1PeriodPriorq,"JAN17"
2PeriodPrior,DEC17
2PeriorPriorq,"DEC17"
CurrentPlanYear,FY 2017
CurrentPlanYearq,"FY 2017"

If the current week is in February 2017 and the previous period (where period is presumably a month) is January 2017, how is the period 2 months prior 10 months later (December 2017) instead of 2 months earlier (December 2016)?

Is this a homework assignment?

Last edited by Don Cragun; 05-20-2017 at 04:23 PM..
Sponsored Links
    #7  
Old Unix and Linux 05-20-2017
SIMMS7400 SIMMS7400 is online now
Registered User
 
Join Date: Apr 2016
Last Activity: 21 October 2017, 6:08 AM EDT
Posts: 128
Thanks: 28
Thanked 3 Times in 3 Posts
Don -

Thank you for the reply.

I'm sorry for passing along bad requirements. Our firm is now responsible for some work admins used to do at this particular client therefore I am going through and establishing automation on many pieces of intraday business processes as most of it is manual - and this is one of the tasks.

Here is the correct data set :


Code:
CurrentWeek,05/20/17
CurrentWeekq,"05/20/17"
CurrentPeriod,MAY17
CurrenttPeriodq,"MAY17"
1PeriodPrior,APR17
1PeriodPriorq,"APR17"
2PeriodPrior,MAR17
2PeriorPriorq,"MAR17"
CurrentPlanYear,FY 2017
CurrentPlanYearq,"FY 2017"

I guesss my concern is when CurrentPeriod hits Jan and then Feb and how to return prior year to return 1PeriodPrior or 2PeriodPrior.

Thank you!
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Parsing a fixed column text file in sed wvdeijk Shell Programming and Scripting 4 06-25-2015 04:23 PM
Parsing text file jacobs.smith Shell Programming and Scripting 7 08-15-2012 06:20 PM
Parsing text file comp8765 Shell Programming and Scripting 3 03-18-2012 05:39 PM
Column wise file parsing. navojit dutta Shell Programming and Scripting 5 02-02-2009 03:21 AM
Text File Parsing Djlethal Shell Programming and Scripting 2 02-27-2008 02:31 AM



All times are GMT -4. The time now is 06:23 AM.