awk work with time change in csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk work with time change in csv file
# 1  
Old 09-05-2011
awk work with time change in csv file

Hi,

i have csv input file looks like below

3rd field is date and time field i want to change it with user supplied date and time says
Code:
year=2011
		month=09
		day=05
		hour=11
                count=2

when count is say 10 then first ten records should pick and it should increment the second fields by 1 for each record. if user suplies count = 61
then second should increment upto 59 then minute should increment and second again should with 01.


HTML Code:
Event: "07709367129","12","2008/05/12-03-15-00.00",,"GBP",,,,,,,,"07709367129","000000000001234","0","100C",,,,,,,,,,,,,,,"822",,"Rj-aZlKEwBkAAADPAAAAIgACh1YAAAAA~2",,,
Event: "07709367129","12","2008/05/12-03-30-00.00",,"GBP",,,,,,,,"07709367129","07852306109","0","100C",,,,,,,,,,,,,,,"822",,"Rj-aiFKEwBkAAADPAAAAHgAChf8AAAAA~2",,,"00:

outut should look like below

Code:
Event: "07709367129","12","2011/09/05-11-00-00.00",,"GBP",,,,,,,,"07709367129","000000000001234","0","100C",,,,,,,,,,,,,,,"822",,"Rj-aZlKEwBkAAADPAAAAIgACh1YAAAAA~2",,,
Event: "07709367129","12","2011/09/05-11-00-01.00",,"GBP",,,,,,,,"07709367129","07852306109","0","100C",,,,,,,,,,,,,,,"822",,"Rj-aiFKEwBkAAADPAAAAHgAChf8AAAAA~2",,,"00:

if count is given 61 then

it should pick 61 records from file minute should start with 00 and second with 00 , 01 ..... 59 then minute should increment to 01:00 for 60 th record and 01:01 for 61 st



i have written awk code its not working as expected.

Code:
year=2011
                month=09
                day=05
                hour=11
                count=2
rm -f tt.tmp
com=$year/$month/$day-$hour-

min=00

i=0


awk ' BEGIN { FS=OFS="," } { x=$count ; for( i = 0; i <= x; i++ ) {$3="'$com'""'$min-'""$i"":00"
  print $0}}' tt >> tt.tmp



any rectification or any other thought ?


thanks,
Raghavendra

Last edited by radoulov; 09-05-2011 at 09:30 AM.. Reason: Code tags.
# 2  
Old 09-05-2011
try this .. change the count value as needed ..
Code:
$ cat filename
#!/bin/bash
year=2011; month=09; day=05; hour=11; count=2; min=00; dummy=0
sed -n "1,${count}p" inputfile | nawk -F, '{$3 = ""; print}' > temp.txt
awk '{$1 = ""; $2 = ""; $3 = ""; print }' temp.txt > temp1.txt
awk '{print $1,$2,$3}' temp.txt > temp2.txt
for (( c=$dummy; c<$count; c++ ))
do
        echo "\"$year/$month/$day-$hour-$min-$c-00\"" >> loop_content
        if [ "$c" -gt 58 ]; then
        c=$dummy
        count=`expr $count - 59`
        min=`expr $min + 1`
        echo "\"$year/$month/$day-$hour-$min-$c-00\"" >> loop_content
        fi
done
paste -d, temp2.txt loop_content temp1.txt | sed 's, ,\,,g'
rm temp2.txt temp1.txt temp.txt loop_content
$
$ bash filename
Event:,"07709367129","12","2011/09/05-11-00-0-00",,,,"GBP","07709367129","000000000001234","0","100C","822","Rj-aZlKEwBkAAADPAAAAIgACh1YAAAAA~2"
Event:,"07709367129","12","2011/09/05-11-00-1-00",,,,"GBP","07709367129","000000000001234","0","100C","822","Rj-aZlKEwBkAAADPAAAAIgACh1YAAAAA~2"
$

# 3  
Old 09-06-2011
Thanks jayan its working with little modification thanks lot !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date format change in a csv file

Hi, We have csv file where date is coming in MM/DD/YYYY HH:MM:SS (06/23/2015 20:59:12) in multiple places But we need to change the date format to DD/Mon/YYYY HH:MM:SS (23/Jul/2015 20:59:12) using shell script. Please let us know how can we achieve the same. (16 Replies)
Discussion started by: dholea
16 Replies

2. Shell Programming and Scripting

Get first and last time entries for a given date in CSV file

CSV date sorted file has multiple entries for most dates. Need to eliminate all but the first and last entries of each date, being the start and end times for that day. 2009-11-20,23:57:46 2009-11-20,23:58:46 2009-11-20,23:59:46 2009-11-21,00:00:45 2009-11-21,00:01:46 2009-11-21,00:02:45... (2 Replies)
Discussion started by: mdennis6
2 Replies

3. Shell Programming and Scripting

Need to change date format in a csv file using awk

Example: Input csv file 00245DLS,Sitel Ocala,12/31/2014,18:45,1.00,7.00,0.00,0.00 00245DLS,Sitel Ocala,12/31/2014,19:00,-1.00,-1.00,-1.00,-1.00 00245HB,Charlotte,01/01/2015,00:00,-1.00,-1.00,-1.00,0.00 Output csv file 00245DLS,Sitel Ocala,2014/12/31,18:45,1.00,7.00,0.00,0.00 00245DLS,Sitel... (8 Replies)
Discussion started by: adit
8 Replies

4. Shell Programming and Scripting

Datestamp format 2nd change in csv file (awk or sed)

I have a csv file formatted like this: 2014-08-21 18:06:26,A,B,12345,123,C,1232,26/08/14 18:07and I'm trying to change it to MM/DD/YYYY HH:MM for both occurances. I have got this: awk -F, 'NR <=1 {print;next}{"date +%d/%m/%Y\" \"%H:%m -d\""$1 "\""| getline dte;$1=dte}1' OFS="," test.csvThis... (6 Replies)
Discussion started by: say170
6 Replies

5. Shell Programming and Scripting

awk change one value in csv based on another value in the record

I've found 2 great discussions on this forum that are tied to my question, but for some reason, neither solution works for me. I have a CSV file with many records, up to 150+ at some times. Many records have a value of H in $1. For those records, I need to add today's current date in $20. I'm... (4 Replies)
Discussion started by: mrvitas
4 Replies

6. Shell Programming and Scripting

Strip time from CSV File?

Hi, I've been trying (and failing miserably) all morning to strip from a CSV file the time from it. Can somebody point me in the right direction on how to do this using sed or awk? The file looks like: "James","07/20/2009-14:40:11" "Steve","08/06/2006-02:34:37"... (5 Replies)
Discussion started by: nmuntz
5 Replies

7. UNIX for Advanced & Expert Users

Time validation in a csv file

Hi, Im having a hard time in creating a script with the following conditions below. I have a csv file generated which is updated every 5 mins and it contains a timestamp in it. for example: time data 00:00 1 00:05 0 00:10 6 00:15 3 however, there is a time that... (4 Replies)
Discussion started by: mdap
4 Replies

8. UNIX for Dummies Questions & Answers

How to work with fields of a csv file?

I need to insert data into a perticular field of a csv file, lets say second field. Can any one help me to do this? I found that we can do it with sed. can any one guide me to accomplish this? thanks in advance. (12 Replies)
Discussion started by: praveen_b744
12 Replies

9. Shell Programming and Scripting

Work CSV file with awk loop

I need to converts a CSV file from Format "A" into Format "B", where the first field is repeated in a loop with a counter. I'am quite sure that this is with AWK possible burt the "Forum Search Function" doesn't work at the moment. Format "A" A1;B1 ;B2 ;B3 A2;C1 ;C2 ;C3 ... (2 Replies)
Discussion started by: frieling
2 Replies

10. UNIX for Dummies Questions & Answers

How to change the file modification time of a file on nfs mount point

Hi I am accessing a file on nfs mounted device, after completing using of the file, i am tring to restore the access time and modification times of the file. So i got the previous modified time of the file using stat() function and trying to set the date and time for the file, To set these... (6 Replies)
Discussion started by: deepthi.s
6 Replies
Login or Register to Ask a Question