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
How to use Perl to merge multi-line into single line happyday Shell Programming and Scripting 3 05-11-2009 05:42 AM
Writing a simple loop in perl docdudetheman Shell Programming and Scripting 3 04-08-2009 03:05 PM
Perl script to search a line and copy it to another line ammu Shell Programming and Scripting 3 12-29-2008 05:12 PM
simple socket programming in perl zedex Shell Programming and Scripting 2 08-23-2008 06:31 PM
a simple perl gusla UNIX for Dummies Questions & Answers 3 04-17-2002 03:01 AM

Reply
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 06-17-2009
jimmy_y jimmy_y is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 94
Lightbulb perl 09-06-11 to 11062009, simple one line

Hi Guys,

If want to change the string "09-06-11" to "11062009", i can only think use split to get the array@, the [0],[1],[2], then restructure the sequence.

Is there a simple line to do that?

Thanks

-----Post Update-----

@file_e_tmp = split('-', $ARGV[0]);
$file_date_e = $file_e_tmp[2].$file_e_tmp[1]."20".$file_e_tmp[0];
  #2 (permalink)  
Old 06-17-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 536
Quote:
Originally Posted by jimmy_y View Post
...

If want to change the string "09-06-11" to "11062009", ...
Is there a simple line to do that?...
Code:
perl -e '{$_="09-06-11"; s/(.*)-(.*)-(.*)/$3${2}20$1/; print}'
tyler_durden
Bits Awarded / Charged to durden_tyler for this Post
Date User Comment Amount
06-17-2009 jimmy_y Thanks 200
  #3 (permalink)  
Old 06-17-2009
jimmy_y jimmy_y is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 94
Quote:
Originally Posted by durden_tyler View Post
Code:
perl -e '{$_="09-06-11"; s/(.*)-(.*)-(.*)/$3${2}20$1/; print}'
tyler_durden
Thanks tyler, perl is so nice.
  #4 (permalink)  
Old 06-17-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,315
Quote:
Originally Posted by jimmy_y View Post
Thanks tyler, perl is so nice.
What about awk?

Code:
awk -F- '{print $3 $2 "20" $1}'
Bits Awarded / Charged to Franklin52 for this Post
Date User Comment Amount
06-17-2009 jimmy_y N/A 200
  #5 (permalink)  
Old 06-17-2009
jimmy_y jimmy_y is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 94
Quote:
Originally Posted by Franklin52 View Post
What about awk?

Code:
awk -F- '{print $3 $2 "20" $1}'
Hi Frank, not sure how to run this command. please advice
i run
"awk -F- '{print $3 $2 "20" $1} 09-06-11"?
"awk -09-06-11- '{print $3 $2 "20" $1}"?

Thanks
  #6 (permalink)  
Old 06-17-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,400
Quote:
Originally Posted by jimmy_y View Post
Hi Frank, not sure how to run this command. please advice
i run
"awk -F- '{print $3 $2 "20" $1} 09-06-11"?
"awk -09-06-11- '{print $3 $2 "20" $1}"?

Thanks
try it this way
Code:
echo "09-06-11"|awk -F- '{print $3 $2 "20" $1}'
or this sed will do
Code:
echo "09-06-11"|sed 's/\(.*\)-\(.*\)-\(.*\)/\3\220\1/g'
Bits Awarded / Charged to vidyadhar85 for this Post
Date User Comment Amount
06-17-2009 jimmy_y N/A 200
Reply

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 02:56 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