unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* how to manipulate data like awk or perl when visiting a file
@ 2008-12-29  4:14 reader
  2008-12-30 14:34 ` Kevin Rodgers
       [not found] ` <mailman.3568.1230647701.26697.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 8+ messages in thread
From: reader @ 2008-12-29  4:14 UTC (permalink / raw)
  To: help-gnu-emacs

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?





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to manipulate data like awk or perl when visiting a file
       [not found] <mailman.3478.1230524085.26697.help-gnu-emacs@gnu.org>
@ 2008-12-29  6:02 ` rustom
  2008-12-29  6:19   ` poppyer
  2008-12-29  6:14 ` Xah Lee
  1 sibling, 1 reply; 8+ messages in thread
From: rustom @ 2008-12-29  6:02 UTC (permalink / raw)
  To: help-gnu-emacs

On Dec 29, 9:14 am, 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?

There was a discussion on something like this a few days ago. See
http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/77dc549480d95f92#


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to manipulate data like awk or perl when visiting a file
       [not found] <mailman.3478.1230524085.26697.help-gnu-emacs@gnu.org>
  2008-12-29  6:02 ` how to manipulate data like awk or perl when visiting a file rustom
@ 2008-12-29  6:14 ` Xah Lee
  2008-12-30  6:59   ` Harry Putnam
       [not found]   ` <mailman.3532.1230620390.26697.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 8+ messages in thread
From: Xah Lee @ 2008-12-29  6:14 UTC (permalink / raw)
  To: help-gnu-emacs

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/^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to manipulate data like awk or perl when visiting a file
  2008-12-29  6:02 ` how to manipulate data like awk or perl when visiting a file rustom
@ 2008-12-29  6:19   ` poppyer
  0 siblings, 0 replies; 8+ messages in thread
From: poppyer @ 2008-12-29  6:19 UTC (permalink / raw)
  To: help-gnu-emacs


rustom <rustompmody@gmail.com> writes:

: On Dec 29, 9:14 am, 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?
:
: There was a discussion on something like this a few days ago. See
: http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/77dc549480d95f92#

This seems not so relevant.

One way I can think of is to replace TAB to | first
and then use orgtbl-mode, the Org Table editor to do the work.

Is there any way without replace TAB first and manipulate them directly?

Cheers,
poppyer


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to manipulate data like awk or perl when visiting a file
  2008-12-29  6:14 ` Xah Lee
@ 2008-12-30  6:59   ` Harry Putnam
       [not found]   ` <mailman.3532.1230620390.26697.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 8+ messages in thread
From: Harry Putnam @ 2008-12-30  6:59 UTC (permalink / raw)
  To: help-gnu-emacs

Xah Lee <xahlee@gmail.com> writes:

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

Thanks for your thoughtful answer. Interesting pages you have.

I got pretty interested reading your comparison of perl vs elisp. 

What prompted my question here was that I had no access to shell tools
or perl on a specific machine I was on right then, so it got me to
thinking why I never see much mention of using elisp for those kinds
of jobs.

Its an interesting subject but in fact I'm rarely in that situation
so usually rely on shell tools awk and perl.  Those I have some small
grasp of.

Your examples may lead me to work on elisp more than I have.

Thanks again.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to manipulate data like awk or perl when visiting a file
  2008-12-29  4:14 reader
@ 2008-12-30 14:34 ` Kevin Rodgers
       [not found] ` <mailman.3568.1230647701.26697.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 8+ messages in thread
From: Kevin Rodgers @ 2008-12-30 14:34 UTC (permalink / raw)
  To: help-gnu-emacs

reader@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

Are you familiar with M-| (shell-command-on-region)?

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to manipulate data like awk or perl when visiting a file
       [not found]   ` <mailman.3532.1230620390.26697.help-gnu-emacs@gnu.org>
@ 2008-12-30 14:57     ` Ted Zlatanov
  0 siblings, 0 replies; 8+ messages in thread
From: Ted Zlatanov @ 2008-12-30 14:57 UTC (permalink / raw)
  To: help-gnu-emacs

On Tue, 30 Dec 2008 00:59:28 -0600 Harry Putnam <reader@newsguy.com> wrote: 

HP> I got pretty interested reading [Xah's] comparison of perl vs elisp. 

HP> What prompted my question here was that I had no access to shell tools
HP> or perl on a specific machine I was on right then, so it got me to
HP> thinking why I never see much mention of using elisp for those kinds
HP> of jobs.

HP> Its an interesting subject but in fact I'm rarely in that situation
HP> so usually rely on shell tools awk and perl.  Those I have some small
HP> grasp of.

The biggest problem with ELisp file processing vs. Perl/awk/etc. is that
efficient line-by-line processing is not possible.  Thus you're limited
to either byte offsets or what will fit in a buffer.  This is a big
inconvenience for large files.

Also, concise one-liners are trivial with Perl and awk, while Emacs
one-liners are painfully verbose (with the one saving grace that $
doesn't show up much in ELisp code).  By the time you're on the third
screen line, you've forgotten what you needed in the first place.

Ted


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to manipulate data like awk or perl when visiting a file
       [not found] ` <mailman.3568.1230647701.26697.help-gnu-emacs@gnu.org>
@ 2008-12-30 15:02   ` Richard Riley
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Riley @ 2008-12-30 15:02 UTC (permalink / raw)
  To: help-gnu-emacs

Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:

> reader@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
>
> Are you familiar with M-| (shell-command-on-region)?

See Xah Lee's excellent pages too:

http://xahlee.org/emacs/emacs_unix.html


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-12-30 15:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.3478.1230524085.26697.help-gnu-emacs@gnu.org>
2008-12-29  6:02 ` how to manipulate data like awk or perl when visiting a file rustom
2008-12-29  6:19   ` poppyer
2008-12-29  6:14 ` Xah Lee
2008-12-30  6:59   ` Harry Putnam
     [not found]   ` <mailman.3532.1230620390.26697.help-gnu-emacs@gnu.org>
2008-12-30 14:57     ` Ted Zlatanov
2008-12-29  4:14 reader
2008-12-30 14:34 ` Kevin Rodgers
     [not found] ` <mailman.3568.1230647701.26697.help-gnu-emacs@gnu.org>
2008-12-30 15:02   ` Richard Riley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).