The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-30-2009
lalelle lalelle is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 43
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 (permalink)  
Old 03-30-2009
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool 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 (permalink)  
Old 03-30-2009
lalelle lalelle is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 43
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 (permalink)  
Old 03-30-2009
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink 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 (permalink)  
Old 03-31-2009
summer_cherry summer_cherry is online now Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,092
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;

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0