Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Desktop
User Name
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.


  Search this Thread
Old 05-04-2008, 05:06 PM   #1
Registered: May 2005
Location: Serbia
Distribution: Debian, Ubuntu, Red Hat, Gentoo
Posts: 64

Rep: Reputation: 15
Import fixed-width column text document in Calc

I have a problem, our software produces reports that is formated in fixed width columns, it does not have an option to genereate csv or other delimited format. I didn't find a way to import such a document in Calc. MS Excel does this very well and we are using it at the moment, but we are considering to change to Linux. Is there any way?
Old 05-04-2008, 07:05 PM   #2
Registered: Mar 2008
Posts: 73

Rep: Reputation: 16
I don't know how to do it inside of OpenOffice, but here
is a simple shell script that will do it.

# Shell script to change fixed width file to
# pipe delimited file.

# data line is like: AAAbbbCCCCddddddddddEEEEEEEEEE

PIPEFILE="${ORIGFILE%%.*}-pipe.dat" # Create output file

# Create a set of separate files based on each fixed column
cut -c1-3 "$ORIGFILE" > F1.out.$$
cut -c4-6 "$ORIGFILE" > F2.out.$$
cut -c7-10 "$ORIGFILE" > F3.out.$$
cut -c11-20 "$ORIGFILE" > F4.out.$$
cut -c21- "$ORIGFILE" > F5.out.$$

# Put the separate files together using pipe to separate
# the pipe is a common delimiter because it seldom appears
# in ordinary data.
paste -d"|" F?.out.$$ > "$PIPEFILE"
rm -f F?.out.$$ # remove temp files
I called the script fixed2pipe.bash
Use chmod +x fixed2pipe.bash
using the original fixed data file called fixedwidth.dat,
the output file will be called fixedwitdh-pipe.dat,

Run the command like this
./fixed2pipe.bash fixedwidth.dat

The original file looks like:

The new file has:

which can load easily into OpenOffice.
Old 05-04-2008, 09:00 PM   #3
Registered: Oct 2004
Posts: 58

Rep: Reputation: 15
Several ways
1. Rename document to .csv and open in (which will go to Calc)
2. Copy to clipboard and paste into Calc
3. Use Text to Columns

All three options give you the same dialog which allows fixed or delimited width import.
Old 05-05-2008, 04:23 PM   #4
Registered: May 2005
Location: Serbia
Distribution: Debian, Ubuntu, Red Hat, Gentoo
Posts: 64

Original Poster
Rep: Reputation: 15
Number two showed to be most usefull. You just have to click up between columns to separate them in proper way. Thank you for this help!

Last edited by Marel; 05-05-2008 at 04:28 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 03:36 PM
LXer: Extending Turning into a document conversion tool LXer Syndicated Linux News 0 05-09-2007 01:46 PM can't use text database in calc or base brickbat Linux - Software 2 07-13-2005 03:43 PM
loading from text file using column width spyghost Programming 5 11-03-2003 02:34 PM
data import into openoffice calc general4172 Linux - Software 0 09-24-2003 01:45 PM > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 01:00 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration