Use of SED in Perl or any other options


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Use of SED in Perl or any other options
# 1  
Old 12-21-2008
Bug 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
# 2  
Old 12-21-2008
Hi,

try:

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

HTH Chris
# 3  
Old 12-22-2008
Power Thanks! Chris its wrking finr on cammnd prmpt but not in perl script

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
# 4  
Old 12-22-2008
Hi,

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

This should work in perl:

Code:
#! /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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rewrite sed to perl or run sed in perl

I am having trouble re-writing this sed code sed -nr 's/.*del(+)ins(+).*NC_0{4}(+).*g\.(+)_(+).*/\3\t\4\t\5\t\1\t\2/p' C:/Users/cmccabe/Desktop/Python27/out_position.txt > C:/Users/cmccabe/Desktop/Python27/out_parse.txt in perl Basically, what the code does is parse text from two fields... (12 Replies)
Discussion started by: cmccabe
12 Replies

2. Programming

[Perl] Different printf formating for different print options

Hi, Struggling with single quotes, double quotes, etc. I want to print a header line, followed by lines with actual values, based on a print option. In real life it is going to be something like 15 print options and 50 values. Output will be 1 header and several value lines. In this example... (5 Replies)
Discussion started by: ejdv
5 Replies

3. Shell Programming and Scripting

[Solved] Sed error - multiple number options to `s' command

Hi All, I am having two files (file1 & file2) and a filelist.txt file below. file1: $$STRINGVAR1=5 $$STRINGVAR2=10 $$LAST_UPD_DT_TBL1=12/12/2010 12:00:00 $$STRINGVAR3=100 $$LAST_UPD_DT_TBL2=01/01/2010 12:00:00... (8 Replies)
Discussion started by: Chandru_Raj
8 Replies

4. Shell Programming and Scripting

Perl script to check uname options

I am trying to read the /etc/security/limits.conf file to match with my specifications. Specification should match below : nofile=131072 noproc=131072 memlock=3500000 I have written a perl script to read the file: #!/usr/bin/perl $FILE1 = "/home/sriram/perl_scripts/limits.conf";... (2 Replies)
Discussion started by: sriram003
2 Replies

5. Shell Programming and Scripting

Perl simple text menu with options

Hopefully I'm in the right place. Im new to the forums and linux! I'm looking to add a menu to my perl hangman game i have created. The menu will use user input for the desired option and then perform the operation indicated. I would like something along the lines of: Welcome to Hangman... (1 Reply)
Discussion started by: jahburmski
1 Replies

6. Shell Programming and Scripting

Run perl script, with command-line options

Hello everyone, I have a perl script which takes various command line options from user like : test.pl -i <input_file> -o <output_file> -d <value> -c <value> Now I have multiple input files in a directory: <input_file_1> <input_file_2> <input_file_3> <input_file_4> ..... .... ...... (6 Replies)
Discussion started by: ad23
6 Replies

7. Shell Programming and Scripting

cut, sed, awk too slow to retrieve line - other options?

Hi, I have a script that, basically, has two input files of this type: file1 key1=value1_1_1 key2=value1_2_1 key4=value1_4_1 ... file2 key2=value2_2_1 key2=value2_2_2 key3=value2_3_1 key4=value2_4_1 ... My files are 10k lines big each (approx). The keys are strings that don't... (7 Replies)
Discussion started by: fzd
7 Replies

8. Shell Programming and Scripting

Using perl to get options from command line

Hi all, I want to get options from command line by perl. usage() options: -h Show this help message and exit -t Name of tester --timeout Set the timeout -l ... (1 Reply)
Discussion started by: Damon_Qu
1 Replies

9. Shell Programming and Scripting

Sed options

I have a file with name input_file.spec. This file has records like: Record #: 1 rec_len = 590 rec_id = 31229 filler_4 = " " orig_id = 902162988 seqnum = 138960799 lrnid ... (3 Replies)
Discussion started by: Ajay_84
3 Replies

10. Shell Programming and Scripting

sed h and g options

Hi .. Happy New Year.. If i do a sed -e ' /BEGIN/,/END/{ h /xxx/{ g p } } ' temp1 I have two queries in this script 1.Will the block between BEGIN and END be stored in the hold buffer before executing the /xxx/ .. (9 Replies)
Discussion started by: sivasenthil_k
9 Replies
Login or Register to Ask a Question