![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Amend Unix hostname | venhart | UNIX for Advanced & Expert Users | 3 | 03-11-2009 03:45 PM |
| amend ftp to sftp | new2ss | Shell Programming and Scripting | 1 | 02-16-2009 12:26 AM |
| Amend the size of a Partition Error | drchris | SUN Solaris | 2 | 02-25-2008 06:58 AM |
| sed to replace only one istance in a file at a time | ramaramarama | UNIX for Dummies Questions & Answers | 1 | 10-19-2007 01:07 PM |
| replace time format | happyv | Shell Programming and Scripting | 16 | 04-25-2007 03:39 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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 |
|
|||||
|
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)
|
|
||||
|
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;
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|