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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



subhotech1
New User

Dec 21, 2008, 10:22 PM

Post #1 of 2 (1045 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/"

and

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 !!!
Subhotech


FishMonger
Veteran / Moderator

Dec 22, 2008, 6:26 AM

Post #2 of 2 (1038 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.

Code
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