Out put with select date. Help !!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Out put with select date. Help !!!
# 1  
Old 02-24-2006
Out put with select date. Help !!!

If I have a flatfile like vote.dat

NAME | SEX | DATETIME | VOTE
Jason|M|2005-12-10 08.01.30|Y
Benson|M|2005-12-10 12.01.00|Y
William|M|2005-12-10 08.01.09|Y
Nick|M|2005-12-11 09.01.07|Y
Pascal|M|2005-12-11 01.01.06|Y
Mickey|F|2005-12-12 12.01.30|Y

How can I write a korn script to have the out put files depend on the date like

20051210.dat
Jason|M|2005-12-10 08.01.30|Y
Benson|M|2005-12-10 12.01.00|Y
William|M|2005-12-10 08.01.09|Y


20051211.dat
Nick|M|2005-12-11 09.01.07|Y
Pascal|M|2005-12-11 01.01.06|Y


20051212.dat
Mickey|F|2005-12-12 12.01.30|Y

Thanks,
# 2  
Old 02-24-2006
Code:
#! /usr/bin/ksh

while IFS=\| read a b c d
do
    print $a\|$b\|$c\|$d >> $(print "$c" | nawk -F[-\ ] '{print $1$2$3".dat"}')
done < vote.dat

# 3  
Old 02-24-2006
Code:
awk 'BEGIN{FS="[ |]"}
NR>1 { f = $3 ".dat" ; gsub(/-/,"",f)
  if (f!=old_f) close(old_f)
  print  > f ; f = old_f
}' vote.dat

# 4  
Old 02-27-2006
Thanks, it works !
# 5  
Old 02-27-2006
OOOp ! one more question ?
If I would like to sort it , how to I sort and remove the duplicate line in file
print $1$2$3".dat" ???, i dont want to sort for vote.dat because yyyyddmm.dat need to be sorted and uniq -d this file , how do you do it ?

Thanks.

==========
#! /usr/bin/ksh

while IFS=\| read a b c d
do
print $a\|$b\|$c\|$d >> $(print "$c" | nawk -F[-\ ] '{print $1$2$3".dat"}')
done < vote.dat

==========
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to put a date from last week into a filename?

I have written three database queries to extract data from yesterday, last week and last month. I need a way to name the output files something like this : "Daily 2014-05-21", "Weekly 2014-05-19" & "Monthly 2014-05-01" if I run them today ( 2014-05-22 ). I can specify the output file name from... (5 Replies)
Discussion started by: djohnson123
5 Replies

2. UNIX for Dummies Questions & Answers

Select all files in a folder based on creation date (ls command)

Hi All, <Re-posting in Correct group> I'm trying to select all the files in a folder that starts with a particular name format and are created in a gven date range using 'ls' command...but i'm not successful.... Example : I'm trying to see all the text files in a folder who names start... (6 Replies)
Discussion started by: Satya C1
6 Replies

3. Shell Programming and Scripting

PS3 and SELECT, is it possible to put a line break?

Hi all, Before I give up on using SELECT for my first attempt at creating a menu driven script, can anyone please advise if it is possible to include a line break for PS3, I've tried putting in a \n and it does not work. Tried for both bash and ksh and both gives the same result. Preference... (3 Replies)
Discussion started by: newbie_01
3 Replies

4. UNIX for Dummies Questions & Answers

Select text between current date and output to new txt file

Hi guys, brand new to this thread and very very new to UNIX...so go easy please! Anyway I have a file that looks like this: >>-------------------------------------------------------------------------- Date/Time/Eng. : 2012-06-22 / 00:26 / DS Reported problem : (SD) ... (5 Replies)
Discussion started by: martin0852
5 Replies

5. Shell Programming and Scripting

How to put date range from a perl & sql script

Hi Guys, Can someone please help me on adding/inserting a variable date to an sql scipt? Basically I want to assign a 7 days date range. As shown below.. #!/usr/bin/perl use strict; use Env qw(ORACLE_HOME); my $SQLPLUS='/opt/oracle/product/10.1.0/db_1/bin/sqlplus -S... (1 Reply)
Discussion started by: pinpe
1 Replies

6. Programming

How to put variable date from SQL Script

Hi Guys, Can someone please help me on adding/inserting a variable to an sql scipt? Basically I want to assign today's date. As shown below.. set head off; set linesize 300; set pagesize 200; spool /opt/oracle/temp/output.txt select value,count(*) as totalcount from pmowner.pinpebasev... (11 Replies)
Discussion started by: pinpe
11 Replies

7. Shell Programming and Scripting

Select ip and date using sed or gawk

1.56.253.48 - - "GET " 1.6.253.48 - - "GET " 1.65.253.48 - - "GET " 1.65.253.48 - - "GET " 1.63.53.48 - - "GET " 1.65.253.48 - - "GET " 1.16.23.48 - - "GET " 1.64.25.48 - - "GET " need command which give the output 1.6.253.48 - 09/Nov/2009:07:02:24 1.65.253.48 -... (7 Replies)
Discussion started by: sagar_evc
7 Replies

8. Shell Programming and Scripting

to put date at the end of each line

#!/bin/ksh if test -f file6.txt then rm file6.txt fi a=`date +"%F"` awk '{print $0,"$a"}' file3.txt > file6.txt ----------------------------------------------------------------- i need to append date at the end of each line in file 3 and o/p it to file6.txt (3 Replies)
Discussion started by: ali560045
3 Replies

9. UNIX for Dummies Questions & Answers

how do I put a date and time in a file name

I want to copy a file to another file so that the current time and date are in the file name. For example I want to copy file profit.txt to a file name in the format of profit_YYYYMMDDHHmm.txt where YYYY is year, MM is number of the month DD is the number of day of the month, HH is the hour of... (2 Replies)
Discussion started by: jhamm
2 Replies
Login or Register to Ask a Question