Date wise calculations?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date wise calculations?
# 15  
Old 04-18-2016
I'm really sorry for that rudi, but still no luck
Code:
Code:
egrep "([^ ]+ +){11}2015.(03|04)|POST"  EXTRACT.txt | awk -F "|" {'print $12'}
POST_DATE
POST_DATE
2015.12.02
 
2015.12.10
2015.12.28
2015.12.03
2015.12.21
2015.12.09
2015.12.09
2015.11.25
2015.12.01
2015.12.24
 
2015.12.09

# 16  
Old 04-18-2016
Without a decent real life sample I can't help further.
# 17  
Old 04-18-2016
Rudi,

PF the data below, I have masked lot of things, we have some more columns, dint included him here thinking it may not be required.


Code:
Code:
1008	116823	33	A	118	1431240091	15	ABCD 6510		2015.09.09	XXXXXXXXXX	d	XXXXXXXXXX	2015.12.01	1	33
1008	116823	33	A	118	-1142149389	23.05	ABCD 6510		2015.09.09	XXXXXXXXXX	d	XXXXXXXXXX	debit	XXXXXXXXXX	2015.12.01
1008	116823	33	A	118	-392122611	18.9	ABCD 6510		2015.10.05	XXXXXXXXXX	d	XXXXXXXXXX	2015.12.01	1	39
1008	116823	33	A	118	-54753935	84.34	ABCD 6510		2015.10.05	XXXXXXXXXX	d	XXXXXXXXXX	2015.12.01	1	39
1008	116823	33	A	118	1966358768	2.91	ABCD 6510		2015.10.06	XXXXXXXXXX	d	XXXXXXXXXX	2015.12.01	1	22
1008	116823	33	A	118	469200831	13.47	ABCD 6510		2015.09.14	XXXXXXXXXX	d	XXXXXXXXXX	2015.12.01	1	23
1008	116823	33	A	118	1284265141	2.76	ABCD 6510		2015.10.26	XXXXXXXXXX	d	XXXXXXXXXX	2015.12.01	1	1
1008	116823	33	A	118	-1911676106	4	ABCD 6510		2015.10.19	XXXXXXXXXX	d	XXXXXXXXXX	2015.12.01	1	1
1008	116823	33	A	118	-2064109421	40	ABCD 6510		2015.11.18	XXXXXXXXXX	d	XXXXXXXXXX	2015.12.01	1	11
1008	116823	33	A	118	2079801662	25	ABCD 6510		2015.09.15	XXXXXXXXXX	d	XXXXXXXXXX	2015.12.01	1	28
1008	116823	33	A	118	1954930603	7	ABCD 6510		2015.10.19	XXXXXXXXXX	d	XXXXXXXXXX	2015.12.01	1	1
M	Mqq	BAN	DISPLAY_NAME	IT_A_I	TR_SEC_I	ANT	DESCRIPTION	TRANSACTION_DATE	POST_DATE	CHECK_NUMBER	Methid	LNAME	ASOF	Tstatus	Tcat


Expecting this will help ... Have included even the column name below

Last edited by nikhil jain; 04-18-2016 at 04:23 AM..
# 18  
Old 04-18-2016
Listen, this is getting lengthy. There's no | delimiter as indicated in post#15. Using the default field separators, field 12 is
Code:
awk '{print $12}' file
d
d
d
d
d
d
d
d
d
d
d

Unless you take a decent step back, start over and present a meaningful and useful specification, I won't be in a position to help.
# 19  
Old 04-18-2016
rudi,

Really sorry, I had just copied it from excel just noticed that some of the column i had to wrap it to mask.

Plz chk below if it helps


Code:
Code:
1008	116823	33	A	118	1431240091	282483235	1431240091	15	ABCD 6510		2015.09.09	XXXXXXXXXX	d	XXXXXXXXXX
1008	116823	33	A	118	-1142149389	282483125	-1142149389	23.05	ABCD 6510		2015.09.09	XXXXXXXXXX	d	XXXXXXXXXX
1008	116823	33	A	118	-392122611	282483183	-392122611	18.9	ABCD 6510		2015.10.05	XXXXXXXXXX	d	XXXXXXXXXX
1008	116823	33	A	118	-54753935	282483182	-54753935	84.34	ABCD 6510		2015.10.05	XXXXXXXXXX	d	XXXXXXXXXX
1008	116823	33	A	118	1966358768	282483181	1966358768	2.91	ABCD 6510		2015.10.06	XXXXXXXXXX	d	XXXXXXXXXX
1008	116823	33	A	118	469200831	282483225	469200831	13.47	ABCD 6510		2015.09.14	XXXXXXXXXX	d	XXXXXXXXXX
1008	116823	33	A	118	1284265141	282483140	1284265141	2.76	ABCD 6510		2015.10.26	XXXXXXXXXX	d	XXXXXXXXXX
1008	116823	33	A	118	-1911676106	282483161	-1911676106	4	ABCD 6510		2015.10.19	XXXXXXXXXX	d	XXXXXXXXXX
1008	116823	33	A	118	-2064109421	282483043	-2064109421	40	ABCD 6510		2015.11.18	XXXXXXXXXX	d	XXXXXXXXXX
1008	116823	33	A	118	2079801662	282483253	2079801662	25	ABCD 6510		2015.09.15	XXXXXXXXXX	d	XXXXXXXXXX
1008	116823	33	A	118	1954930603	282483160	1954930603	7	ABCD 6510		2015.10.19	XXXXXXXXXX	d	XXXXXXXXXX
M	Mqq	BAN	DISPLAY_NAME	IT_A_Id	Aitem_id	Btransid	TR_SEC_I	ANT	DESCRIPTION	TRANSACTION_DATE	POST_DATE	CHECK_NUMBER	Methid	LNAME

# 20  
Old 04-18-2016
Here is a commented version of the script I suggested:
Code:
#!/bin/ksh
# Set IAm to the final component of the pathname used to invoke this script.
IAm=${0##*/}

# If the number of operands given to this script is not 3, print a usage
# message to the standard error output and exit.
if [ $# -ne 3 ]
then	printf 'Usage: %s year.month1 year.month2 filename\n' "$IAm" >&2
	exit 1
fi
# Use awk to print any line in the file whose pathname is given by the 3rd
# operand to this script ("$3") where the field separator for lines in the file
# is set to a <period> character (-F'.') and:
# 1.  the input line number is 1 (NR==1): to print the header, or (||)
# 2.  the 1st field followed by the field separator followed by the 2nd field
#	is the string specified by the 1st operand to this script (-v ym1="$1")
#	and ($1 FS $2==ym1): to print lines matching the 1st given year
#	and month, or (||)
# 3.  the 1st field followed by the field separator followed by the 2nd field
#	is the string specified by the 2nd operand to this script (-v ym2="$2")
#	and ($1 FS $2==ym2): to print lines matching the 2nd given year
#	and month.
awk -F'.' -v ym1="$1" -v ym2="$2" 'NR==1 || $1 FS $2==ym1 || $1 FS $2==ym2' "$3"

Is this enough explanation, or is there something that still isn't clear?

If the date you want to process is in the 12th field and the field separator is a <tab> character and there is no header line (or the header line does not appear as the 1st line and doesn't need to be copied to the output) as in your latest sample input, you could try the following script instead:
Code:
#!/bin/ksh
# Set IAm to the final component of the pathname used to invoke this script.
IAm=${0##*/}

# If the number of operands given to this script is not 3, print a usage
# message and exit.
if [ $# -ne 3 ]
then	printf 'Usage: %s year.month1 year.month2 filename\n' "$IAm" >&2
	exit 1
fi

awk -F'\t' -v ym1="$1" -v ym2="$2" '
#NR == 1 {
# The following code to print the header has been removed because the sample
# data does not have a header line.
#	# Print the header line and skip further processing for this line.
#	print
#	next
#}
{	# Split the 12th tab separated field into the ymd[] array using
	# <period> as the field # separator within this field.
	split($12, ymd, /[.]/)
	#printf("$12=%s, ymd[1]=%s, ymd[2]=%s\n", $12, ymd[1], ymd[2])

	# Print this line if ym1 or ym2 is the same string as ymd[1] "." ymd[2].
	if(ym1 == ymd[1] "." ymd[2] || ym2 == ymd[1] "." ymd[2])
		print
}' "$3"

If someone wants to try either of the above scripts on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.

As has been said before, giving us data that is not at all representative of the data you want to process, not telling us what the field separator is in the data you want to process, and continually changing your requirements is a huge waste of everyone's time.

I hope the above helps you, but if this still doesn't meet your requirements, we have little incentive to try to help if your requirements change again.
This User Gave Thanks to Don Cragun For This Post:
# 21  
Old 04-18-2016
Don & rudi ,

Thanks a lot , sorry to trouble you folks with my wrong input. will make sure not to repeat again.

Don,

Thanks for the explaination, It helps us lot (novice users).
How do i print headers in beginning, Can you plz help there, I tried doing m geting syntax error.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert values into a file 0 as per the date wise

Hi The file contains 12 months of date and less than 12 months of data I want to display if date filed less than 12 months of data I want to insert a value amount 1 to amount4 0 and dates as well. 12345|Date|cntry|amount1|amount2|amount3|amoun4... (2 Replies)
Discussion started by: jagu
2 Replies

2. Shell Programming and Scripting

Extract count of string in all files and display on date wise

Hi All, hope you all are doing well! I kindly ask you for shell scripting help, here is the description: I have huge number of files shown below on date wise, which contains different strings(numbers you can say) including 505001 and 602001. ... (14 Replies)
Discussion started by: VasuKukkapalli
14 Replies

3. Shell Programming and Scripting

Generate sum of a particular column date wise

Hi All, I have a file with below content 01/22/2014,23:43:00,1742.8, 01/22/2014,23:43:00,1742.8, 01/22/2014,23:44:00,1749.06666666667, 01/25/2014,23:45:00,2046.45, 01/25/2014,23:43:00,1742.8, 01/25/2014,23:44:00,1749.06666666667, 01/25/2014,23:45:00,2046.45, 01/25/2014,23:43:00,1742.8,... (4 Replies)
Discussion started by: villain41
4 Replies

4. Shell Programming and Scripting

How to read files by Server Creation date wise?

Hi All, I would have many files in the server with xyz*.dat -- Static file name Physical files: xyz1.dat - 01PM xyz2.dat - 02PM xyz3.dat - 03PM In present version we are using for f in $file_name do fname=`ls $f | grep -v ^'\|'$ | sed s/' '/'\\ '/g` .... sqlldr... (4 Replies)
Discussion started by: Dharv
4 Replies

5. Shell Programming and Scripting

Date Calculations using script!!

Hi all, Thanks in Advance , i am very new to programming part in script i think using some caluations+ sed command only we can do this process in script. for exampl: i have file in that one line is like this using sed i can replace the date and all but my requirement is The... (3 Replies)
Discussion started by: anishkumarv
3 Replies

6. Solaris

delete files by date wise

Hi guys, I want to delete files from june 13 to june 30, using rm command can any one tell me the sintax to remove. I ahve hunderd of core files in my /var dir. so i want to clear last month core files. Thanks in Advance.:)) (2 Replies)
Discussion started by: kurva
2 Replies

7. 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

8. Shell Programming and Scripting

Need help with Date calculations in ksh

Hi Gurus, I am writing a script where we enter two dates, one a FROM DATE and the other a TO DATE. I need to validate that difference between the two dates is always less than or equal to 60 days. I could not find any date utility in ksh that could help me with this. Finally, I am deciding... (5 Replies)
Discussion started by: jidsh
5 Replies

9. UNIX for Dummies Questions & Answers

Date Calculations

I need to be able to use the current date and calculate 7 days ago to be stored in another variable to be passed to a file in my Unix shell script. I need the date in the following format: date '+%m/%d/%Y' or 05/16/2006 How do I calculate date minus 7 days or 1 week ago? (8 Replies)
Discussion started by: mitschcg
8 Replies

10. Shell Programming and Scripting

To extract data of a perticular interval (date-time wise)

I want a shell script which extract data from a log file which contains date and time-wise data and i need the data for a perticular interval of time...what can i do??? (3 Replies)
Discussion started by: abhishek27
3 Replies
Login or Register to Ask a Question