CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
SED/ AWK in Perl or any other regular expression


New User

Dec 21, 2008, 10:22 PM

Post #1 of 2 (1702 views)
SED/ AWK in Perl or any other regular expression Can't Post

Hi Folks,

I am working on a data extraction script in perl.I am a begineer in perl and shell scripting. So i need your inputs to solve the script problem.

I have data coming from database in the format :-

<b> _ABC (Apply Changes) (p) </b> _EFG | HIJ | KLM | WER
<b> _E3R (Apply Changes) (p) </b> _UIG | IJJ | OLK | JWR

I need :-

_ABC \t _EFG \t HIJ \t KLM \t WER
_E3R \t _UIG \t IJJ \t OLK \t JWR [ \t = tab delimited ]

I have tried sed and awk on the comand prompt :-

echo "<b> _ABC (Apply Changes) (p) </b> _EFG | HIJ | KLM | WER" | sed "<b> /(.*/) </b> /(.*/) | /(.*/) | /(.*/) /\1 \2 \3 \4/"


echo "<b> _ABC (Apply Changes) (p) </b> _EFG | HIJ | KLM | WER" | awk 'BEGIN{OFS="\t"}{print $2,$7,$9,$11,$13}'

The awk on the command prompt is atleast giving me the desired output. But i am not able to embed this piece of code into perl script a i am missing some escape char.

Please suggest

- Thanks !!!

Veteran / Moderator

Dec 22, 2008, 6:26 AM

Post #2 of 2 (1695 views)
Re: [subhotech1] SED/ AWK in Perl or any other regular expression [In reply to] Can't Post

Why would you want to embed either of those into a Perl script?

The perl language was built around the combination of awk, sed, grep and a number of other standard unix utilities.

Here's your awk solution converted to perl.

my $str = "<b> _ABC (Apply Changes) (p) </b> _EFG | HIJ | KLM | WER"; 

print join("\t", (split(/ /, $str))[1,6,8,10,12]);


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives