[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to manipulate data like awk or perl when visiting a file
From: |
Xah Lee |
Subject: |
Re: how to manipulate data like awk or perl when visiting a file |
Date: |
Sun, 28 Dec 2008 22:14:57 -0800 (PST) |
User-agent: |
G2/1.0 |
On Dec 28, 8:14 pm, rea...@newsguy.com wrote:
> I want to get a leg up on how I might manipulate a file like I can
> with shell tools or awk/perl.
>
> Examples: I want to display only the first field of lines 30 thru 75
> I want to reverse field 1 and 5 and print those plus 6 of
> each line.
> I want to add up the numbers that appears in field 7 of
> lines 11 through 28 printing the total to ~/sumtot.txt
>
> I'd like to see a few basic examples and maybe I'll be able to get the
> idea enough to do some of that when I need to.
>
> I don't really want to start way at the beginning of elisp to get
> started. I hoped maybe there are some examples like that available
> in existing info documents.
>
> I haven't noticed much talk here about those kinds of chores so maybe
> elisp isn't a good choice for that?
do you want to do this as interactive use or do you mean how to do it
in elisp?
For elisp, here's a example:
• How To Process A File Line By Line In Elisp
http://xahlee.org/emacs/elisp_process_lines.html
for your task, perhaps it's easier to simply read all content in a
file, use split-string so that each line becomes a list item, then use
split-string again on each item so that you got the fields.
Of course, you can also just write your code in awk or perl, and have
a emacs wrapper to call them as emacs commands. See
• Elisp Wrapper For Perl Scripts
http://xahlee.org/emacs/elisp_perl_wrapper.html
For interactive use, depending what specifically what you want to do,
but it might be easier to simply use shell-command or shell-command-on-
region, and call your sed awk.
Xah
∑ http://xahlee.org/
☄