Re: [LONG] Re: regex, negations, grep, find and replace (a few questions)



On Tue, 27 Nov 2007, in the Usenet newsgroup alt.os.linux, in article
<474ca109$0$29249$ba620e4c@xxxxxxxxxxxxxx>, goarilla wrote:

Moe Trin wrote:

[Jeez Kevin, do you think you can figure out how to trim off the stuff
you aren't replying to?]

i doubt you typed all these command's perfectly right from the first
time ? i really think you had to test some of them before typing them
here

Well, let's see... there were four commands shown.

1) grep -vE '^([%\[ ]|Score|$)' /var/spool/slrnpull/score |
cut -d' ' -f1 | sort | uniq -c | column

2) ls `echo $PATH | tr ':' ' '` | grep -Evc '(:|^$)'

3) history | cut -c7- | tr '|' '\n' | sed 's/^ *//' | cut
-d' ' -f1 | sort -u | wc -l

4) zcat rfcs/rfc-index.txt.11.05.07.gz | sed 's/^$/\%/' | tr -d '\n'
| tr '%' '\n' | grep '^[0-9]' | tr -s ' ' | grep -v 'Not Issued'
| sed 's/.*Status: //' | tr -d '\)' | sort | uniq -c | column

Number two is child's play. Number three (which does contain a less
optimum sequence) is a bit harder, but I doubt if I spent more than
30 seconds creating it. Number one is more about the use of egrep to
select multiple data fields from a file - the manipulation is somewhat
simple, and could be done better. I probably spent more time looking
at the data file than actually writing the command - again, we're
talking about a few seconds - certainly less than a minute. Number
four? Yeah, that probably took ten minutes to put together. In case
you haven't figured, I've been using *nix for a "few" years (well over
twentyfive). One thing I've learned to do is when I create a command
sequence is to throw a copy into a "this worked" file so that I can
reuse the command later, or modify it to suit new circumstances.

The reason I'm showing these commands is not to dazzle the newbies.
These are cut-and-pastes, showing the command and the results. The
whole idea is to provoke thought - "how did he do that?". I actually
do expect the inquisitive to cut-and-paste these commands into their
own terminal shell, and see what results they get. Poke at it - see
what makes it work. If you _use_ the command line, this stuff
really shouldn't be that difficult. A neighbor of mine teaches an
"Intro To UNIX" class at the local Community College (2 year school
allowed to grant Associates degrees), and the second and third commands
are used early in the class (3 nights a week, 3 hours a night, 12 weeks)
to demonstrate the concept of chaining commands. The fourth command
would not be used (the 'rfc-index' file is 19k lines, and 842Kbytes),
but one-liners of similar complexity ARE taught. Oh, and as an "Intro"
class, it has no prerequisites - if you're in this school, you can sign
up for this class. The students get a lot of homework, but they also
get decent "hand-outs" and in the lab are expected to work together
(but not during tests).

This stuff really isn't rocket science. Look at the problem. What
steps do you need to go through to solve the problem. Try some
(piping the output to 'less' lets you evaluate the individual steps
without getting overwhelmed with the whole file). Remember that the
task is to solve whatever problem was presented. Results count. Pretty,
fast, or elegant can come later if needed. The usual problem is first
thinking out possible steps to solve the problem. But you start by
looking at the data to see how/what your desired information is in
that file. The idea isn't to solve the problem using one, or two
commands, but to use what you are familiar with to do a piece of the
job, which can then be passed to another tool to do something else,
and eventually, we arrive at the "answer" what ever it may be.

Old guy
.



Relevant Pages

  • Re: egrep help
    ... it was not the prettiest or most efficient way. ... attempt to show what the commands do rather than how to do it the ... you showed as it's a tool for concatenating files, ... Showing him the best way to use those tools to do that job is like ...
    (comp.unix.shell)
  • Re: WinLogo/SARPC
    ... SARPC it seems to load, showing the 3 windows, and accept simple commands ...
    (comp.sys.acorn.apps)
  • Switchboard items
    ... of the name, I want it to give me items (school names) for each person (Jane, ... Joe, and Bob). ... i won't let me creat new items, so I have to give commands for each name, ... I want to execute the command after creat new ...
    (microsoft.public.access.tablesdbdesign)
  • RE: Switchboard items
    ... of the name, I want it to give me items (school names) for each person (Jane, ... Joe, and Bob). ... i won't let me creat new items, so I have to give commands for each name, ... I want to execute the command after creat new ...
    (microsoft.public.access.tablesdbdesign)
  • Re: problem adding new record to access database table
    ... Where have you placed this code, is there something of a sub or a function. ... Definitly are you using and showing to much code. ... the commands to the dataadapter. ...
    (microsoft.public.dotnet.framework.adonet)