Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How to process variable length fields in delimited file.

by shadowsong (Pilgrim)
on Oct 06, 2016 at 11:37 UTC ( [id://1173394]=note: print w/replies, xml ) Need Help??


in reply to How to process variable length fields in delimited file.

Hi dbach355

Seeing as how The number of fields is fixed, the number of fixed field lengths and variable field lengths varies - if all you need is another file with custom delimiters; you can achieve this with a one-liner:

perl -lawpe "$_=qq|$F[0]\\f$F[1]\\f$F[2]\\f$F[3]|" in.txt > out.txt

The offset within the @F array denotes each input field in your file; so offset 0 would represent ssn, offset 1 employee number and so on; simply craft your output line how you'd like it... See http://www.perl.com/pub/2004/08/09/commandline.html for additional command line options.

Cheers,
Shadowsong

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1173394]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found