LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 12-06-2006, 09:49 PM   #1
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("jessie", "squeeze"), Linux Mint (Serena), XUbuntu
Posts: 221

Rep: Reputation: 24
Looking for Column Mode editor (like IBM's XEDIT or KEDIT)


Greetings LQ'ers

I used to use XEDIT on IBM/Mainframes and KEDIT in DOS, and they both had the
ability to delete or copy certain columns of long text files (all the way down,
not just one line at a time). Anyone who has used those editors knows what I
mean. VI has something called column mode, but I have never been able to figure
out how to make it do what I want.

I am amazed to have found no easy way (short of Perl, Python, C) to delete
certain columns (or truncate lines) in an ASCII file.

Open to all suggestions. SED, a special line truncation command, or an
(open source) editor with column mode.

Thanks lots!

PS -- There is an open source dummy editor called XEDIT -- it doesn't do what IBM's
XEDIT did.
 
Old 12-06-2006, 10:30 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
(Haven't used any of the editors you're describing.)

This can be done many ways. Here's an idea with awk.

Scenario: 4-column ASCII text file. Columns are delimited by pipes ('|'). We want to omit the 3rd column and keep delimiters intact.

Code:
[hector@troy ~]$ awk 'BEGIN{ FS="|"; OFS="|" }{ print $1, $2, $4 }' data-file
As for the truncation command, what is it you're trying to do exactly?
 
Old 12-06-2006, 10:38 PM   #3
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
Hi.

The cut command can operate on columns as well as fields. See man cut for details.

If you need to do it interactively, I think an editor called le has that feature, and see http://en.wikipedia.org/wiki/Comparison_of_text_editors for a table of feature comparisons ... cheers, makyo
 
Old 12-06-2006, 11:01 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The closest in "vi" may be the blockwise visual mode. Position the cursor to the first character in the column. Then press "CTRL-v". Now you can move the cursor to the right and down to select the other characters in the block.

Then you can press "x" to delete the column, or "y" to yank (copy) the column or block. This could be used to select a column or even a block from the middle of the page.
I don't think that pasting it would result in the extra spaces needed being added to the end of short lines however. I'm not an expert in using vi. You could use a regular expression to delete certain characters on a line within a range of characters. The percent character is used to select a line range covering the entire document. ":%s/^...//" would delete the first three characters of every line for example. It is also possible to yank regions into a register and paste that register later.

I've used a similar editor program (dos based) at work to quickly take a file listing and convert it into a script by inserting a command and pasting the filenames twice, before making certain global changes to one of the columns.
A similar thing could be done in vi:
:%s/^\(.*\)$/mv \1 \1.bu/

This would create a rename script adding .bu to a file list. Of course a bash script to do the same thing whould be a snap as well.

Last edited by jschiwal; 12-06-2006 at 11:02 PM.
 
Old 12-07-2006, 09:45 AM   #5
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("jessie", "squeeze"), Linux Mint (Serena), XUbuntu
Posts: 221

Original Poster
Rep: Reputation: 24
Thank you all! My willingness to use sed indicated I was game for
awk, but hadn't yet figured out if it would help! Knowing about le
sounds great, and I'll have to check out cut. Re: Anomie's question about truncate. In this particular case, I wanted
to remove the final four columns of a fixed column width file (it had
been created by printf's in C.), thus truncate. In fact, the general
solutions you presented for column editing were even more what I
was hoping for.
 
Old 12-07-2006, 10:22 AM   #6
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
Hi.

More specific information on le ... cheers, makyo
Quote:
# Version: 1.13.4
# Entered-date: 2006-11-30
# Description: LE has many block operations with stream and rectangular blocks, can edit both unix and dos style files (LF/CRLF), is binary clean, has hex mode, can edit text with multibyte character encoding, has full undo/redo, can edit files and mmap'able devices in mmap shared mode (only replace), has tunable syntax highlighting, tunable color scheme (can use default colors), tunable key map, tunable menu. It is slightly similar to Norton Editor for DOS, but has more features.

http://www.boutell.com/lsm/lsmbyid.cgi/000084
 
Old 12-07-2006, 11:26 AM   #7
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
Re: Anomie's question about truncate. In this particular case, I wanted
to remove the final four columns of a fixed column width file (it had
been created by printf's in C.), thus truncate.
In that case, gawk may be an option for you. It can handle fixed-width fields/columns using the FIELDWIDTHS special variable.

Example:
Code:
[helen@troy ~]$ gawk 'BEGIN{ FIELDWIDTHS = "4 10 4 5"; OFS=""; }
{ print $1,$2,substr($3,1,3); }' data-file
In this case I've identified that there are four columns in data-file, which are 4 bytes, 10 bytes, 4 bytes, and 5 bytes. Then I am printing to stdout only the first three columns. And.. I am only printing the first 3 bytes of the third column.
 
Old 12-07-2006, 04:43 PM   #8
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("jessie", "squeeze"), Linux Mint (Serena), XUbuntu
Posts: 221

Original Poster
Rep: Reputation: 24
le -- block mode

Hi -- makyo. I tried out LE's block mode.

At first I couldn't find what I was looking for, but then
I did. LOVELY.

For others on this thread.
F4 B to begin a block
F4 E to close the block (selected text now highlighted)
Default block type is rows, but then do an F4 T to
change type of block to columns. It is now easy to delete
selected columns in any range of lines in the file.

I have been crunching data urgently for past couple of days
and this just saved me a bunch of time!!

Thanks a lot!

Last edited by pcardout; 12-07-2006 at 05:13 PM.
 
Old 12-08-2006, 05:46 AM   #9
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
Hi, pcardout.

I'm glad it worked out. The volume of key combinations in le is almost over-whelming:
Code:
le --dump-keymap
so it may take some re-training if your fingers are used to vi or emacs ... cheers, makyo
 
Old 12-10-2006, 01:55 PM   #10
KWTm
Member
 
Registered: Jan 2004
Distribution: Kubuntu 14.04 (Dell Linux-preinstalled laptop + 2 other laptops)
Posts: 117

Rep: Reputation: 21
KDE editors (KATE or KWrite) have block mode

You said:
I am amazed to have found no easy way (short of Perl, Python, C) to delete certain columns (or truncate lines) in an ASCII file.

Well, yes, there is. I, in turn, am amazed that with all the replies so far, no one has mentioned that KWrite and KATE (the KDE Advanced Text Editor that comes with any basic KDE installation) have block mode.

Main Menu > E)dit > B)lock selection mode, or use Ctrl-Shift-B, to switch between the two. Then you can select one or more columns of text "all the way down", or from a particular line to another line of your choice. You basically highlight in a rectangular area, and you can cut, paste, copy, etc. And then you can switch back to non-block mode for normal editing.

There must be some GNOME equivalent if you're not a KDE user; perhaps someone more familiar with GNOME can add a comment here. Of course, if you want to mess around with sed, awk, or Python, that's your choice ...
 
  


Reply

Tags
editors, text



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
text editor at rescue mode? abtimoteo Ubuntu 3 09-18-2005 08:58 AM
I can't believe it... xedit ruined my C project... diam0nd Linux - Software 13 08-30-2004 05:52 PM
how to make an editor do as emacs's shell mode does? icoming Programming 2 05-21-2004 09:50 AM
Launch an editor from desktop in su mode? jkpalmer52 Linux - Newbie 13 11-14-2003 11:28 AM
Text Editor in Console Mode ? membrax Linux - Hardware 5 12-28-2002 11:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 02:35 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration