converting fixed width file to a delimited file

212 views
Skip to first unread message

jabir m

unread,
Aug 27, 2014, 5:07:53 PM8/27/14
to unix-and-perl-...@googlegroups.com
Hi -

I have to convert a file which is a fixed width into a pipe (|) delimited file. what is the Logic I can use here ( I mean how can I achieve to remove the trailing white spaces and put the delimiter.
I was trying to do it using sed command it end-up all the white spaces (between the string)  replaced with delimiter.

thanks
Jabir

Keith Bradnam

unread,
Aug 27, 2014, 6:21:56 PM8/27/14
to unix-and-perl-...@googlegroups.com
Can you include a before/after example of how you would want your file to look like?

jabir m

unread,
Aug 27, 2014, 10:28:10 PM8/27/14
to unix-and-perl-...@googlegroups.com
Thanks Keith..

Here is the sample data

5 fields  and field length  (10,4,5,10,5)


Fixed width 

ABC       12  abcdeJabir  KK 12345

ABC       12  abcdeJabir  KK 12345

ABC       12  abcdeJabir  KK 12345



After conversion (field separator is :)

ABC:12:abcde:Jabir KK:12345

ABC:12:abcde:Jabir KK:12345

ABC:12:abcde:Jabir KK:12345

Claudius Kerth

unread,
Aug 28, 2014, 10:50:48 AM8/28/14
to unix-and-perl-...@googlegroups.com
Hi Jabir,

try this on a Mac:

sed -E 's/ +/|/g' filename

or this on Linux:

sed -r 's/ +/|/g' filename

claudius


--
You received this message because you are subscribed to the Google Groups "Unix and Perl for Biologists" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unix-and-perl-for-bi...@googlegroups.com.
To post to this group, send email to unix-and-perl-...@googlegroups.com.
Visit this group at http://groups.google.com/group/unix-and-perl-for-biologists.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages