|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
Quote:
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
|
|||
|
|||
|
Quote:
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
|
|||
|
|||
|
Code:
perl -lne 'do {while (/\s(\w+)=(\S+)/g){print "$1 is equal to $2"}} if /^specialword/' inputfile |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|