Use of SED in Perl or any other options

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 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" | sed " /(./) | /(./) | /(.*/) /\1 \2 \3 \4/"

but i am not getting the desired output.

  • Thanks !!!
    Subhotech

Hi,

try:

awk 'BEGIN{OFS="\t"}{print $2,$7,$9,$11,$13}' file

HTH Chris

Thanks! Chris .. it is working fine on command prompt

when i am trying to embed tis code to the perl script it is giving me errors.

I have added the escape char the perl script i.e
my $output =~ `print $records | awk 'BEGIN\{OFS\="\t"\}{print \$2,\$7,\$9,\$11,\$13}'`;

but i am sure i am missing something on the escape char.
please suggest !!
-Thanks!
Subhotech

Hi,

yes, awk you would have to use from the command line
or call via system().

This should work in perl:

#! /usr/bin/perl -w

$ex="<b> _ABC (Apply Changes) (p) </b> _EFG | HIJ | KLM | WER";
@f=split(/\s+/,$ex);
$out=join("\t",$f[1],$f[6],$f[8],$f[10],$f[12]);

print $out; 

HTH Chris