Perl searching special words in lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl searching special words in lines
# 1  
Old 07-30-2010
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.
# 2  
Old 07-30-2010
Quote:
Originally Posted by alinalin
... 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
This User Gave Thanks to durden_tyler For This Post:
# 3  
Old 08-02-2010
Quote:
Originally Posted by durden_tyler
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
Code:
perl -lne 'do {while (/\s(\w+)=(\S+)/g){print "$1 is equal to $2"}} if /^specialword/' inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extract lines with specific words with addition 2 lines before and after

Dear all, Greetings. I would like to ask for your help to extract lines with specific words in addition 2 lines before and after these lines by using awk or sed. For example, the input file is: 1 ak1 abc1.0 1 ak2 abc1.0 1 ak3 abc1.0 1 ak4 abc1.0 1 ak5 abc1.1 1 ak6 abc1.1 1 ak7... (7 Replies)
Discussion started by: Amanda Low
7 Replies

2. UNIX for Dummies Questions & Answers

searching words & print prefixed string after it

I have a text which I divided them into sentences and now printed them in a rows. I want to get the list of most of words ( the, and, a) and print 5 words after them (so 6 with the word itself). I have created an acceptfile with those rows and using grep but I have rows that have these words more... (2 Replies)
Discussion started by: A-V
2 Replies

3. Shell Programming and Scripting

Finding my lost file by searching for words in it

Got a question for you guys...I am searching through a public directory (that has tons of files) trying to find a file that I was working on a longggggg time ago. I can't remember what it is called, but I do remember the content. It should contains words like this: Joe Pulvo botnet zeus... (5 Replies)
Discussion started by: statichazard
5 Replies

4. Shell Programming and Scripting

Awk: Searching for length of words between slash character

Dear UNIX Community, I have a set of file paths like the one below: \\folder name \ folder1 \ folder2 \ folder3 \ folder4 \\folder name \ very long folder name \ even longer name I would like to find the length of the characters (including space) between the \'s. However, I want... (6 Replies)
Discussion started by: vnayak
6 Replies

5. UNIX for Dummies Questions & Answers

Searching for multiple words on a line in any order issue

Hi again I have figured out how to be able to sort through lines in a file with multiple words in any order and display them using this command: cat file | grep -i $OPTION1 | grep -i $OPTION2 | grep -i $OPTION3 OPTION1 is 2008, OPTION2 is Mar, OPTION 3 is Tue Result: Tue Mar 25... (4 Replies)
Discussion started by: semaj
4 Replies

6. Shell Programming and Scripting

searching regular expressions with special characters like dot using grep

hi everybody I am a new user to this forum and its previous posts have been very useful. I'm searching in a file using grep for patterns like 12.13.444 55.44.443 i.e. of form <digit><digit>.<digit><digit>.<digit><digit><digit> Can anybody help me with this. Thanks in advance (4 Replies)
Discussion started by: jpriyank
4 Replies

7. Shell Programming and Scripting

searching for words between delimeters from the rear

Hi, i need to pick up dates and times from the file names which are of unequal length. The dates and time are delimited by dot. I am interested in getting the strings between the delimeter for fields -3, -4, -5 from behind (rear) so that the out put looks like : 071118.011300.556 I have... (2 Replies)
Discussion started by: oktbabs
2 Replies

8. Shell Programming and Scripting

Searching words in a file containing a pattern

Hi all, I would like to print words in a file seperated by whitespaces containing a specific pattern like "=" e.g. I have a file1 containing strings like %cat file1 The= some= in wish= born <eof> .I want to display only those words containing = i.e The= , some=,wish= ... (5 Replies)
Discussion started by: sree_123
5 Replies

9. Shell Programming and Scripting

special question, hard to describe in few words...

dear coders, i need some inspiration again... there is something what i always wanted to know... how to code following: value 1: __________ value 2: __________ important: when my "script" starts the display has to be cleared and two lines are shown (see above), the cursor has to be... (2 Replies)
Discussion started by: pseudocoder
2 Replies

10. UNIX for Dummies Questions & Answers

searching and displaying most commonly used words

Hi guys, i need to search the most commonly occuring words in a file and display their counts of about 30000 words and the words shud not be of typ specified in file 2 e. words like is,for,the,an,he,she etc... k. file1: ALICE was beginning to get very tired of sitting by... (2 Replies)
Discussion started by: arunsubbhian
2 Replies
Login or Register to Ask a Question