How to replace and amend value in the same time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace and amend value in the same time
# 1  
Old 03-30-2009
How to replace and amend value in the same time

2009/03/30 08:11:34.553 DFP
2009/03/30 08:11:36.861 PLO

I want it to be

2009/03/30 09:11:34.553 DFP
2009/03/30 09:11:36.861 PLO

and
2009/03/30 23:11:34.553 DFP
2009/03/30 23:11:36.861 PLO

to be

2009/03/30 00:11:34.553 DFP
2009/03/30 00:11:36.861 PLO

Can we use sed or awk here? I don't know how.
# 2  
Old 03-30-2009
Tools Is the follwoing what you are looking for?

Code:
> echo "2009/03/30 08:11:34.553 DFP" | awk '{newh=substr($2,1,2)+1; if (newh==24){newh=00}; printf("%10s %2.2d%8s %3s\n",$1,newh,substr($2,3,10),$3)}'
2009/03/30 09:11:34.553 DFP

> echo "2009/03/30 23:11:34.553 DFP" | awk '{newh=substr($2,1,2)+1; if (newh==24){newh=00}; printf("%10s %2.2d%8s %3s\n",$1,newh,substr($2,3,10),$3)}'
2009/03/30 00:11:34.553 DFP

# 3  
Old 03-30-2009
thanks that's good stuff but columns are not fixed so it could be
2009/03/30 23:11:34.553 DFP
2009/03/30 23:11:34.553 DFP 12[1.24] [1.3]
2009/03/30 23:11:34.553 Pctreas no remark [2.3] (obsolete)
I tested with your code doesn't work

Thanks again
# 4  
Old 03-30-2009
Hammer & Screwdriver what about this then?

Code:
> val1="2009/03/30 23:11:34.553 DFP"
> echo "$val1" | awk '{newh=substr($2,1,2)+1; endv=$3" "$4" "$5" "$6" "$7; if (newh==24){newh=00}; printf("%10s %2.2d%8s %-30s\n",$1,newh,substr($2,3,10),endv)}'
2009/03/30 00:11:34.553 DFP                           

> val1="2009/03/30 23:11:34.553 Pctreas no remark [2.3] (obsolete)"
> echo "$val1" | awk '{newh=substr($2,1,2)+1; endv=$3" "$4" "$5" "$6" "$7; if (newh==24){newh=00}; printf("%10s %2.2d%8s %-30s\n",$1,newh,substr($2,3,10),endv)}'
2009/03/30 00:11:34.553 Pctreas no remark [2.3] (obsolete)

# 5  
Old 03-31-2009
perl

Code:
my %hash=('08'=>'09','23'=>'00');
my @array=('2009/03/30 08:11:34.553 DFP','2009/03/30 23:11:36.861 PLO');
open $fh,"<","a.spl";
map {	my @arr=split("[ :]",$_,3);	print $arr[0]," ",$hash{$arr[1]},":",$arr[2],"\n"} @array;

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Programming

Find gaps in time data and replace missing time value and column 2 value by interpolation in awk

Dear all, I am kindly seeking assistance on the following issue. I am working with data that is sampled every 0.05 hours (that is 3 minutes intervals) here is a sample data from the file 5.00000 15.5030 5.05000 15.6680 5.10000 16.0100 5.15000 16.3450 5.20000 16.7120 5.25000... (4 Replies)
Discussion started by: malandisa
4 Replies

2. Shell Programming and Scripting

Amend File Without Changing Timestamp

Hi, Is it possible to amend a file without changing the last modified date? If it is, how do you do it? If it's not, is there a way to create an empty file with the same timestamp as another file? I know you can use touch -t yyyymmddhhmm.ss filename but, I would want the file to... (4 Replies)
Discussion started by: Ste_Moore01
4 Replies

3. UNIX for Advanced & Expert Users

Amend Unix hostname

Hi, Please could someone advise on the following if possible. I have built a unix server, and was given the wrong hostname. I need to amend the hostname to the correct name. And I don't want to rebuild the server again. I've tried the following to do change : hostname DTCT-TD3FIXI01A... (3 Replies)
Discussion started by: venhart
3 Replies

4. Shell Programming and Scripting

amend ftp to sftp

Hi all, below is my current scriptftp -n << FTPCTRL open $my_ip user $my_user $my_pass ascii prompt off lcd $myDIR cd $ftp_cd $OPS $myfile FTPCTRLI'd like to amend it to sftp mode. Please advise the correct step.I consulted the man pages of sftp and I suppose I should be using the... (1 Reply)
Discussion started by: new2ss
1 Replies

5. Solaris

Amend the size of a Partition Error

Hi guys, I'm fidling around Partition space on SMC and on changing partition size, or assiging an unused partition to "usr", or even trying to alter the disk layout I get: Attempted Format of Partition /dev/dsk/c1t0d0s3 failed with unexpected CIM error: CIM_ERR_FAILED:CIM_ERR_FAILED:... (2 Replies)
Discussion started by: drchris
2 Replies

6. Shell Programming and Scripting

replace time format

Hello All, I have a problem with the following text file. For the field number 5 which is the time format (hh:mm:ss). But I would like to delete "ss" and showing hh:mm only. 00001,CLIENT,Company,1218,N,1:04,35,0.211,0,0.211,1.155531,0:00,0,0,0,0,0,1:04,35,0.211,0,0.211,1.155531,foold... (16 Replies)
Discussion started by: happyv
16 Replies

7. Shell Programming and Scripting

Script to backup multiple files and amend their filenames

Hi, I'm trying to write a command that backs up certain files into my current directory and adds a prefix to the backed up file name. I realise this can be done in a script by specifying each individual file but would like to know if it can be done on one line and made an alias. I have the... (5 Replies)
Discussion started by: m223464
5 Replies
Login or Register to Ask a Question