Pattern matching-3

Pattern matching-3

Post by pavan.. » Fri, 21 Apr 2006 21:24:58



hi Iam pavan . I need to run a perl script that runs on a file and does

the following.

The file may look like like this
pavan.h:

pavan_here  hi how r u
pavan_there  Iam fine
pavan_now    typing

Search for words containing pavan(say)
In the above example it much search for  pavan_here, pavan_there ,
pavan_now    and modify those words such that
1.underscores must be eliminated
2. Next letter to underscore(i.e anyletter after underscore) must
become capital.

I mean to say when I run the script the file must modify to

pavanHere  hi how r u
pavanThere  Iam fine
pavanNow   typing

Hope you understood the problem

It is okay if u know any vim commands also to do this.

 
 
 

Pattern matching-3

Post by ciphe » Fri, 21 Apr 2006 21:59:10


You can use some Regular Expressions inside vi to do that, but I think
youre looking for some app like 'awk' or 'sed'. Take a look at the
man pages for that...
There is a forum, also... comp.lang.awk

For sure they solve your problem.

Regards

 
 
 

Pattern matching-3

Post by Stephane Chazela » Fri, 21 Apr 2006 22:33:10



Quote:> hi Iam pavan . I need to run a perl script that runs on a file and does

> the following.

> The file may look like like this
> pavan.h:

> pavan_here  hi how r u
> pavan_there  Iam fine
> pavan_now    typing
[...] ==>
> pavanHere  hi how r u
> pavanThere  Iam fine
> pavanNow   typing

[...]

perl -pi -e 's{[a-z_]+}{
  ($_ = $&) =~ s/([a-z]+)_?/\u$1/g; $_}xe' pavan.h

--
Stephane

 
 
 

Pattern matching-3

Post by Xicheng Ji » Fri, 21 Apr 2006 23:17:33



> hi Iam pavan . I need to run a perl script that runs on a file and does

> the following.

> The file may look like like this
> pavan.h:

> pavan_here  hi how r u
> pavan_there  Iam fine
> pavan_now    typing

=> Search for words containing pavan(say)
=> In the above example it much search for  pavan_here,
=> pavan_there ,pavan_now    and modify those words
=> such that
=> 1.underscores must be eliminated
=> 2. Next letter to underscore(i.e anyletter
=> after underscore) must become capital.
using Perl:

 perl -pe 's/(?<=pavan)_([a-z])/\u$1/' pavan.h

Quote:> I mean to say when I run the script the file must modify to

> pavanHere  hi how r u
> pavanThere  Iam fine
> pavanNow   typing

> Hope you understood the problem

> It is okay if u know any vim commands also to do this.

under VIM:

:%s/\(pavan\)_\([a-z]\)/\1\u\2

Xicheng

 
 
 

Pattern matching-3

Post by Xicheng Ji » Sat, 22 Apr 2006 00:17:09




> => Search for words containing pavan(say)
> => In the above example it much search for  pavan_here,
> => pavan_there ,pavan_now    and modify those words
> => such that
> => 1.underscores must be eliminated
> => 2. Next letter to underscore(i.e anyletter
> => after underscore) must become capital.
> using Perl:

=>  perl -pe 's/(?<=pavan)_([a-z])/\u$1/' pavan.h
=> :%s/\(pavan\)_\([a-z]\)/\1\u\2

BTW. it might be better to change [a-z] to ., in case of "pavan_There"
where the character right behind the underscore is already capital, you
can still remove the underscore..

in Perl:
perl -pe 's/(?<=pavan)_(.)/\u$1/' pavan.h
in VIM:
:%s/\(pavan\)_\(.\)/\1\u\2

Xicheng

 
 
 

1. Pattern matching and extracting the data which matches the pattern

Help,

I am running Solaris 2.6, and have only ever written scripts for the Korn
Shell......and have the following query......

I have a very long text file ( each line represents a CAD model name ).
Somewhere within the model name (i.e. line of the text file ) , is  the
drawing reference number......this number will always match a particular
pattern of letters, hyphens and numbers - which will not be matched
elsewhere within the remainder of the line.
I need a mechanism to search each line in turn, match the pattern of
letters, hyphens and numbers and extract purely that portion of the line and
write it to a separate file. My problem , is that the pattern could appear
anywhere within each line and the number of fields can differ ( if it was
always in the same place or had a constant number of fields, I would use
'cut' )
For example, an extract from the input file could be :-

LD100 WEIGHT DAMPER              W7A   22 Z  535210043-A  USE30SE99MVS
99/10/26
LD100 GROMMET  GUIDE  ROD          W5D   12 Z  545180058-B  USE30SE99MAK
99/10/26
LD100 GROMMET  GUIDE  ROD          W5D   22 Z  545180058-B  USE30SE99MAK
99/10/26
LD100 BRACKET-CABLE,SELECT       W7A   12 Z  535210034-C  USE06SE99LJL
99/10/26
LD100 BRACKET-CABLE,SELECT       W7A   22 Z  535210034-C  USE06SE99LJL
99/10/26

And I need to extract the data matching the following pattern: nine
numbers,a hypen and a letter and put it in an output file - thus the output
I would like to see is :-

535210043-A
545180058-B
545180058-B
535210034-C
535210034-C

Many thanks in advance for your help

Mark Hounslow
LDV Limited

2. Some i386 cleanups - MTRR, bootflag

3. Pattern Matching Not Working When Pattern Assign To A Variable

4. MySQL on Linux .......

5. ksh pattern matching when pattern is in a variable

6. Q on ps

7. Pattern matching.

8. >2GB files in ext2fs

9. pattern matching help, please

10. KSH Pattern Match Deletions

11. ksh pattern matching

12. Pattern Match

13. Verifying user input via pattern matching