LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   Looking for Column Mode editor (like IBM's XEDIT or KEDIT) (https://www.linuxquestions.org/questions/linux-desktop-74/looking-for-column-mode-editor-like-ibms-xedit-or-kedit-508062/)

pcardout 12-06-2006 09:49 PM

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.

anomie 12-06-2006 10:30 PM

(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?

makyo 12-06-2006 10:38 PM

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

jschiwal 12-06-2006 11:01 PM

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.

pcardout 12-07-2006 09:45 AM

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.

makyo 12-07-2006 10:22 AM

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

anomie 12-07-2006 11:26 AM

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.

pcardout 12-07-2006 04:43 PM

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!

makyo 12-08-2006 05:46 AM

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

KWTm 12-10-2006 01:55 PM

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 ...


All times are GMT -5. The time now is 04:19 PM.