![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| How to find a particular word in perl | Harikrishna | Shell Programming and Scripting | 2 | 04-10-2008 03:35 AM |
| find a word in a file, and change a word beneath it ?? | vikas027 | Shell Programming and Scripting | 2 | 02-13-2008 04:23 PM |
| Removing a specific word from a created list | erest8 | UNIX for Dummies Questions & Answers | 5 | 10-14-2007 05:11 AM |
| Change Position of word character | cedrichiu | Shell Programming and Scripting | 6 | 03-12-2007 01:52 AM |
| List all file which have specified word | aungomarin | UNIX for Advanced & Expert Users | 4 | 01-03-2007 03:37 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Change word in list - PERL
Hi,
probably a newbie question..... But there it goes. ![]() I have a list words. This list is taken out of a file with grep and cut. my @system = (`grep up system_list| cut -d':' -f1` ); system= sm00xp03 sm01ftp02 sm00ssh12 What I want to have is a list, with each of the words in the first list changed and resulting in two words, like this new_list= sr00xp01 sr00xp02 sr01ftp01 sr01ftp02 sr00ssh01 sr00ssh02 The chars that aren't in bold don't change from one list to the other. Any ideia? Thanks in adavance for any help given. |
|
||||
|
Hello...
So let me understand this... 1. the second character always becomes an 'r'. 2. then there are 2 digits, and some number of characters (your example shows one 2 and two 3 character groups) that you don't change in the second list. 3. followed by 2 digits that do change in the second list, and always to a '01' and '02'. Have I got that right? If I have then you might be able to do this with a pattern/substitution (or maybe 2 of them) inside a foreach loop... foreach $word (@list) { chomp($word); # just in case has newline $word =~ s/s/r/; $word =~ s/(\d\d\w+)/$1 . 01\n$1 . 02\n/; $bigword = $bigword . $word; } (@new_list) = $bigword; # you concatenated everything into $bigword with newlines, so they should parse into the array by themselves ... I have no idea of this would work, but it might... Otherwise there are other approaches, mainly to extract the second pattern above and just build the list element by element yourself.... $newctr = 0; foreach $word (@list){ $word =~ /^(\w)/; $first_letter = $1; $word =~ /(\d\d\w+)/ $group = $1; $new_list[$newctr] = $first_letter . 'r' . $group . "01"; $new_list[$newctr + 1] = $first_letter . 'r' . $group . "02"; $newctr += 2; } Now that I know will work, but it isn't very elegant..... |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|