LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices

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

Rep: Reputation: 15
Import fixed-width column text document in OpenOffice.org 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 OpenOffice.org 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, 06:05 PM   #2
rlhartmann
Member
 
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.
Quote:
#!/bin/bash

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

# data line is like: AAAbbbCCCCddddddddddEEEEEEEEEE

ORIGFILE="$1"
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:
AAAbbbCCCCddddddddddEEEEEEEEEE
aaaBBBccccDDDDDDDDDDEEEEEEEEEE

The new file has:
AAA|bbb|CCCC|dddddddddd|EEEEEEEEEE
aaa|BBB|cccc|DDDDDDDDDD|EEEEEEEEEE

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

Rep: Reputation: 15
Several ways
1. Rename document to .csv and open in OpenOffice.org (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, 03:23 PM   #4
Marel
Member
 
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 03:28 PM.
 
  


Reply


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 02:36 PM
LXer: Extending OpenOffice.org: Turning OpenOffice.org into a document conversion tool LXer Syndicated Linux News 0 05-09-2007 12:46 PM
openoffice.org can't use text database in calc or base brickbat Linux - Software 2 07-13-2005 02:43 PM
loading from text file using column width spyghost Programming 5 11-03-2003 01:34 PM
data import into openoffice calc general4172 Linux - Software 0 09-24-2003 12:45 PM


All times are GMT -5. The time now is 03:10 PM.

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