Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by shadowsong (Monk)
on Oct 06, 2016 at 11:37 UTC ( #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
Node Status?
node history
Node Type: note [id://1173394]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2019-05-22 03:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (138 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!