[NTLUG:Discuss] bash to perl

kbrannen@gte.net kbrannen at gte.net
Tue Feb 19 20:34:23 CST 2002


Wrenn, Bobby J. wrote:

> I have the following working but I need to use perl instead of sed. Is that
> possible or do I not understand what I am asking?
> 
> #!/bin/bash
> sed 's/[PS][CV][0-9]*X[0-9]*X[0-9]*[aA-zZ]*/Yes/g' sedtest.csv >
> sedyestest.csv
> 
> I need to do this so I can have a Window$ user mangle the files. I can
> install perl on his machine.


RegExp's that work under sed should work just fine under perl, at least I 
can't think of any exceptions. :-)  So you just need:

perl -ne 's/[PS][CV][0-9]*X[0-9]*X[0-9]*[aA-zZ]*/Yes/g' < input > output

Or if you don't want that on a command line:

---cut---
# perl script
while (<>)
{
	# simplification: s/[PS][CV]\d*X\d*X\d*[aA-zZ]*/Yes/g
	s/[PS][CV][0-9]*X[0-9]*X[0-9]*[aA-zZ]*/Yes/g;
	print;
}
---cut---

and then from the command line:  perl script.pl < input > output

BTW, I suspect you mean "[aA-zZ]" to be "[a-zA-Z]" don't you?

HTH,
Kevin






More information about the Discuss mailing list