Changing CSV files with date . Subtracting date by values
Hi All,
I have a CSV file which is as below. Basically I need to take the year column in it and find if the year is >= 20152 . If that is then I should subtract all values by 6. In the below example in description I am having number mentioned as YYWW so I need to subtract those by -5. Whereever I find the year I have ti subtract by -5. If the year is >201601 then I have to subtrct by -6. The year representation is 52 week. so if the week falls on 03 for example 201403 then the subtraction of -6 will yield 201347. I am planning to do in C++ ,not sure if this possible with awk or sed.
Sorry, for the most part i thought i understood your goal, but i am a bit confused:
Quote:
Originally Posted by arunkumar_mca
and find if the year is >= 20152 .
Is that simply a typo or can the week numbers be either one or two digits? Is the value above in fact reading "201502" or "20152x" or could the second week in 2015 be both represented by "201502" or "20152"?
Either way, it is easily done in awk, but with different algorithms, obviously.
Here is my try for the operation, perhaps a more shorter / better solution can be made ...
Save as program.awk and run as awk -f program.awk input
Year is hardcoded and if variance needs to change, so does zero padding in week variable declaration.
Your input seems the have year on field $5 or $6 which varies on lines, but always on $(NF-1) or a one field before last ?
First my apologize for not putting the actual data.
The Year I should take will always be on column 4. in the above scenario. We are having as P201835. The column I need check the do the subtraction is 2,4,10
I tried changing the awk code like this and ran. It give me the same output as original and no change
Last edited by arunkumar_mca; 11-02-2018 at 12:14 PM..
I'm not sure i follow.
Input now is also inconsistent, with first two rows having 13 fields and last having 12.
Now you say you require fields 2,4 and 10, but on expected output you changed only field 4 for the first two lines and field 5 for the last line.
I have no idea what to do with 2,10, but we can work with 4 and 5 using awk match and regex.
Will it be a good guess now, or are we missing some input again ?
Be sure other fields in line do not match P<year week regex>, since we are using $0
I changed all column in the expected output. If you see in column 4 I have change P201835 to P201829. For column 2 and 10. It is like changing the YYYY , If you look I changed 1832 to 1826. And in Column 10 for last row I changed from RHS_12_1515FF_0706
to RHS_12_1510FF_0706
Ran it and created a same ouput as original
Last edited by arunkumar_mca; 11-02-2018 at 01:17 PM..
All the subtraction done on fields ($2,$10) depends on year on field $4, the variance defined.
If no input on $2 matches string PP<number>, $2 is printed as is, unchanged.
If no input on $10 matches string RHS, $10 is printed as is, unchanged.
I am trying to achieve to get only the month and the day. Example Feb 5 (as you can see if it is feb 1-9) the space is 2. If it is feb 10-28, the space is only 1. I am trying to right a script that will list a directory and shoot an email if there is an activity in last 7 days. I dont really trust... (5 Replies)
Hi All,
I am getting a date from environment variable and want to do some processing by subtracting 2 months from the date passed through the environment variable.
I am trying the following syntax :
date_var=2014-08-31
date_2M_ago='$date_var+"%d%m%y" --$date_var="2 months ago" '... (3 Replies)
I have a CSV file with a date format like this;
11/19/2012 17:37:00,1.372,121.6
11/19/2012 17:38:00,0.743,121.6
Want to change the time stamp to seconds after 1970 so I can get the data in rrdtool. For anyone interested, this is data from a TED5000 unit and is Kwatts and volts.
Needs to... (3 Replies)
I got a statement like below to subtract 1 from given date using teradata. I am looking for a one line unix command to perform the same.
select 'parse_this_record', (DATE '${FILE_DATE}' - 1) (FORMAT 'YYYY-MM-DD');
Input: 2012-02-21
Expected Output: 2012-02-20
PS: One liner because I am... (2 Replies)
Hi all,
I'm using Red Hat Linux and want to move some folders and files around but not change the modified date. Is this possible?
I know cp has a -p flag which seems to do what I want, but this is a large volume of data so copying and deleting would not be feasible. (13 Replies)
how can we add or subtract days from the output of date command in unix...
like if i want to subtract a day from the result of date command like this..
v_date=`date +%Y%m%d`
this wud give me 20080519
now i want to subtract one day from this.. so tht it wud give me 20080518..
how do i do... (1 Reply)
Dear Expert,
Is there a command to do that in Unix?
In such a way that we don't need to actually "write" or
modified the content.
-- monkfan (4 Replies)
I have looked through the forums and found many date / time manipulation tools, but cannot seem to find something that fits my needs for the following.
I have a log file with date time stamps like this:
Jun 21 17:21:52
Jun 21 17:24:56
Jun 21 17:27:59
Jun 21 17:31:03
Jun 21 17:34:07
Jun... (0 Replies)
Hi i am trying to subtract days from current date. For example todays date is 10/03/2006. If i subtract 2 days it should give 8/03/2006. I am also trying to find the access date of a file in dd/mm/yyyy format. Can any one please help in how to do this.
Ramesh (1 Reply)