Parser - multiple in Perl


 
Thread Tools Search this Thread
Top Forums Programming Parser - multiple in Perl
# 1  
Old 01-22-2011
Parser - multiple in Perl

Dear Perl Experts,

Could some body help me to find the solution for my problem below:

Input file:
-----------

THE-0 tsjp
THE-32 tsjp
THE-64 tsjp

Output desired:
---------------

THE-0&&-31 tsjp
THE-32&&-63 tsjp
THE-64&&-95 tsjp

Note:
31 = 0+31,
63 = 32+31,
95 = 64+31,

Many Thanks
# 2  
Old 01-23-2011
Quote:
Originally Posted by askari
...
Input file:
-----------

THE-0 tsjp
THE-32 tsjp
THE-64 tsjp

Output desired:
---------------

THE-0&&-31 tsjp
THE-32&&-63 tsjp
THE-64&&-95 tsjp

Note:
31 = 0+31,
63 = 32+31,
95 = 64+31,

...
Code:
$
$ # show the contents of the input file
$
$ cat input
THE-0 tsjp
THE-32 tsjp
THE-64 tsjp
$
$
$ # Run the Perl one-liner that processes the input file
$
$ perl -lne '/^(.*-)(\d+)(.*)$/ and print "$1$2&&-",($2+31),"$3"' input
THE-0&&-31 tsjp
THE-32&&-63 tsjp
THE-64&&-95 tsjp
$
$

tyler_durden
# 3  
Old 01-23-2011
Hi Tyler_durden,
Thanks alot for your solution
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed parser behaving strange on replacing multiple words in multiple files

I have 4000 files like $cat clus_grp_seq10_g.phy 18 1002 anig_OJJ65951_1 ATGGTTTCGCAGCGTGATAGAGAATTGTTTAGGGATGATATTCGCTCGCGAGGAACGAAGCTCAATGCTGCCGAGCGCGAGAGTCTGCTAAGGCCATATCTGCCAGATCCGTCTGACCTTCCACGCAGGCCACTTCAGCGGCGCAAGAAGGTTCCTCG aver_OOF92921_1 ... (1 Reply)
Discussion started by: sammy777888
1 Replies

2. Shell Programming and Scripting

Perl to run different parser based on digit

The perl parser below works as expected assuming the last digit in the NC_ before the . is a single digit. perl -ne 'next if $. == 1; if(/.*del(+)ins(+).*NC_0{4}(+).*g\.(+)_(+)/) # indel { print join("\t", $3, $4, $5, $1, $2), "\n"; } ' out_position.txt > out1.txt ... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. Shell Programming and Scripting

Update perl code with parser

The below perl code imports the data in the attached document. However, I can not seem to update the perl code to include a parser like in the desired tab of that document. Thank you :). Most of the data for the parse is included in the document except for the gene and RNA which can is... (0 Replies)
Discussion started by: cmccabe
0 Replies

4. Shell Programming and Scripting

Facing problem in XML::parser module in PERL

HI, I have XML file which is having values as Spanish character (UTF-8 encoding). I am using XML::parser module but my code is not able to read those characters. I did goggling but not able to find suitable solution. Anybody please help me out. XML file having characters like: ñ I am... (1 Reply)
Discussion started by: jatanig
1 Replies

5. Shell Programming and Scripting

perl config parser

Hello. Can anybody help me with some sub on perl that can parse config like this: %CFG ( 'databases' => { 'db1' => 'db_11', 'db_12', 'db_13', 'db2' => 'db_21', 'db_22', 'db_23' } 'datafiles' => { 'datadir1' => 'datadir_11', 'datadir_12', 'datadir2' =>... (4 Replies)
Discussion started by: drack
4 Replies

6. Shell Programming and Scripting

xml-parser with perl

Hello I want to write an xml- parser with perl an i use the libary XML::LibXML. I have a problem with the command getElementsByTagName. If there is an empty tag, the getElementsByTagName method returns a NodeList of length zero. how can i check if this is a nodelist of lenght zero?? i... (1 Reply)
Discussion started by: trek
1 Replies

7. Shell Programming and Scripting

Perl XML:Parser help

I am very new to XML. Really I have an excel file that I am trying to read w/ Perl on a Linux machine. I don't have a mod for reading excel files so I have to convert the excel file to xml to be able to read it. I can read the file and everything is ok except...the Number style is being dropped... (0 Replies)
Discussion started by: vincaStar
0 Replies

8. Shell Programming and Scripting

xml parser in perl

hi all i want to read xml file in perl i am using XML::Simple for this. i am not getting how to read following file removing xml file due to some reason (1 Reply)
Discussion started by: zedex
1 Replies
Login or Register to Ask a Question