Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-30-2010
Registered User
 

Join Date: Jul 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Perl searching special words in lines

Hi , i am a new with perl, i want to made a script that find in file rows that start with specil words, as an example a line will start with"
.............................................
specialword aaa=2 bbb=5
.............................................

and to put this in a new file called "newfile"this with:
..............................................
aaa is equal with 2;
bbb is equal with 5;
..............................................


any ideea is very appreciated.

Thanx.
Sponsored Links
    #2  
Old 07-30-2010
durden_tyler's Avatar
Registered User
 

Join Date: Apr 2009
Posts: 1,684
Thanks: 4
Thanked 209 Times in 189 Posts
Quote:
Originally Posted by alinalin View Post
... i want to made a script that find in file rows that start with specil words, as an example a line will start with"
.............................................
specialword aaa=2 bbb=5
.............................................

and to put this in a new file called "newfile"this with:
..............................................
aaa is equal with 2;
bbb is equal with 5;
..............................................
...
Something like this ?


Code:
$
$ cat data.txt
specialword aaa=2 bbb=5
blah blah
blah blah blah
specialword ccc=6 ddd=7 eee=8
blah
blah
specialword fff=9
$
$
$ perl -lne 'do {while (/ (\w+)=(\d+)/g){print "$1 is equal to $2"}} if /^specialword/' data.txt
aaa is equal to 2
bbb is equal to 5
ccc is equal to 6
ddd is equal to 7
eee is equal to 8
fff is equal to 9
$
$

tyler_durden
The Following User Says Thank You to durden_tyler For This Useful Post:
alinalin (08-02-2010)
Sponsored Links
    #3  
Old 08-02-2010
Registered User
 

Join Date: Jul 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by durden_tyler View Post
Something like this ?


Code:
$
$ cat data.txt
specialword aaa=2 bbb=5
blah blah
blah blah blah
specialword ccc=6 ddd=7 eee=8
blah
blah
specialword fff=9
$
$
$ perl -lne 'do {while (/ (\w+)=(\d+)/g){print "$1 is equal to $2"}} if /^specialword/' data.txt
aaa is equal to 2
bbb is equal to 5
ccc is equal to 6
ddd is equal to 7
eee is equal to 8
fff is equal to 9
$
$

tyler_durden

Hi, thank you for your response, this is a good solution, like i told you i am very new with this language and i have a problem your solution recongnize only natural values but i want obtain something like this(i read more about perl but i don't find a solution for "."):
specialword aaa=2.2e-12

and solution:

aaa is equal to 2.2e-12



see you
    #4  
Old 08-02-2010
The Underground
 

Join Date: Sep 2009
Location: ./India/Mumbai
Posts: 889
Thanks: 28
Thanked 179 Times in 174 Posts

Code:
perl -lne 'do {while (/\s(\w+)=(\S+)/g){print "$1 is equal to $2"}} if /^specialword/' inputfile

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
searching regular expressions with special characters like dot using grep jpriyank Shell Programming and Scripting 4 08-12-2009 03:04 AM
searching for words between delimeters from the rear oktbabs Shell Programming and Scripting 2 08-04-2009 11:48 AM
Searching words in a file containing a pattern sree_123 Shell Programming and Scripting 5 05-06-2009 11:28 PM
special question, hard to describe in few words... pseudocoder Shell Programming and Scripting 2 01-01-2009 02:18 AM
searching and displaying most commonly used words arunsubbhian UNIX for Dummies Questions & Answers 2 09-10-2007 07:58 PM



All times are GMT -4. The time now is 04:01 AM.