perl 09-06-11 to 11062009, simple one line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl 09-06-11 to 11062009, simple one line
# 1  
Old 06-17-2009
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? Smilie

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  
Old 06-17-2009
Quote:
Originally Posted by jimmy_y
...

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
# 3  
Old 06-17-2009
Quote:
Originally Posted by durden_tyler
Code:
perl -e '{$_="09-06-11"; s/(.*)-(.*)-(.*)/$3${2}20$1/; print}'

tyler_durden
Thanks tyler, Smilie perl is so nice.
# 4  
Old 06-17-2009
Quote:
Originally Posted by jimmy_y
Thanks tyler, Smilie perl is so nice.
What about awk?

Code:
awk -F- '{print $3 $2 "20" $1}'

# 5  
Old 06-17-2009
Quote:
Originally Posted by Franklin52
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  
Old 06-17-2009
Quote:
Originally Posted by jimmy_y
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'

# 7  
Old 06-17-2009
Quote:
Originally Posted by vidyadhar85
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'

Smilie nice awk, sed. Thanks
***actually i hate trying to remember all those ^~*/\/\ those thing in perl, awk, sed, but they are very nice***
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert bash to simple perl

please delete! (0 Replies)
Discussion started by: SkySmart
0 Replies

2. Shell Programming and Scripting

Simple Perl question

Hello, I'm completely new to Perl and I'm just looking for a quick answer to some code I'm trying to come up with. I'm trying to access a website, part of the URL I want the user to be able to define via standard input. As you can see below I'm still trying to get the syntax. ... (2 Replies)
Discussion started by: wxornot
2 Replies

3. Shell Programming and Scripting

Can Help me in simple perl code

Hi all i want a program have input file .txt and process it then got output Ex: input: King Saud University say hi Mr.Ahmed Cena have a car perl is good ! Dr.john is good! output: KSU say hi Mr.AC have a car perl is good! Dr.John is good! so the process take the String has... (3 Replies)
Discussion started by: abdulelah252
3 Replies

4. Shell Programming and Scripting

Simple perl help - converting numbers

Hi friends, I'm very new to perl and got some requirement. I've input numbers which has size of 17 characters like below: -22500.0000000000 58750.00000000000 4944.000000000000 -900.000000000000 272.0000000000000 I need to convert these numbers from negative to positive and positive... (4 Replies)
Discussion started by: ganapati
4 Replies

5. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

6. Shell Programming and Scripting

Simple Perl error

Hello All, I'm trying to run a simple perl script and have the below error. Tried to google it but could not get a precise solution. Could you please help me out. Can't locate object method "are" via package "equal" (perhaps you forgot to load "equal"?) at ./equal.pl line 9, <STDIN> line 2. ... (3 Replies)
Discussion started by: lovesaikrishna
3 Replies

7. Shell Programming and Scripting

Simple Perl Topic

Hi, I am practicing a very simple perl programming, what i want to do is reverse the string what is wrong with the following Thanks $string = "abcdef"; @array = split(//, $string); $length =length @array for ( i=1;i< $length+1;i++) { print "$_\n"; } (5 Replies)
Discussion started by: ccp
5 Replies

8. Shell Programming and Scripting

Simple perl question

I am totally new to perl. I am modifying someone else's script. I have the following output: # ./some-perlscript A B C D E B - E, is generated through the print command that I put in the script. I want to remove A, it seems it is generated automatically by a custom OS it is querying when... (3 Replies)
Discussion started by: streetfighter2
3 Replies

9. Homework & Coursework Questions

Help with Simple Perl/Python Script

I have the following problem, which I need done in Perl/ or Python using Unix/linux filters... 1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values... (1 Reply)
Discussion started by: Swapnilsagarwal
1 Replies

10. UNIX for Dummies Questions & Answers

a simple perl

not sure if i should post here or "shell programming" anyway, i am just start learning perl. 1 #!/usr/local/bin/perl 2 3 $test1="Iam"; 4 if ($test1=="anything") 5 { 6 print "show me\n"; 7 } when i run the program, it display "show me" all... (3 Replies)
Discussion started by: gusla
3 Replies
Login or Register to Ask a Question