LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-08-2010, 08:51 PM   #16
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879

Quote:
Originally Posted by danielbmartin View Post
My sole source of personal guidance is Email from a friend who lives 600 miles away. He sternly warns me against using sudo for any purpose.

Daniel B. Martin
Daniel, I think you should ask your friend to elaborate
on that statement; it's similar to telling people not
to use a hammer. OK, I don't use a hammer to cut my
nails or comb my hair, or as a means of communications
with my peers; I *do* use it to drive nails into walls,
to to get broken tiles of the walls. sudo is just a
tools; telling you not to use it under any circumstances
is a pretty much crippling suggestion. Giving guidance
on how to use it, or suggesting to take extra caution in
choosing ones actions would be fine.

Considering that in Ubuntu system administration is next
to impossible w/o 'sudo' I'd say your friend needs to
read up on linux, su and sudo himself.

Quote:
If/when I post more questions in this forum,
I will be more specific. I was looking for a clever coding
of the CUT command. I wasn't looking for awk or grep or Bash
or Perl or any other part of Linux which I haven't learned yet.
Maybe some day, but not now.
I accept that you're not ready for "other tools"
at this stage, but that said: I'd be more than
happy to explain what e.g., my sed example does,
and how it does it.


Cheers,
Tink
 
Old 04-08-2010, 09:19 PM   #17
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,099

Original Poster
Rep: Reputation: 288Reputation: 288Reputation: 288
> Daniel, I think you should ask your friend to elaborate
> on that statement ...
> Considering that in Ubuntu system administration is next
> to impossible w/o 'sudo' I'd say your friend needs to
> read up on linux, su and sudo himself.


Without naming my friend/advisor, I can tell you that:
1) He has known me for 30+ years, knows my capabilities and limitations.
2) He has used Linux for *many* years and may be considered an expert.
3) He has been a PC hardware/software professional for *many* years.
4) He is a published author of *many* technical magazine articles.

With that introduction, I quote from his Email regarding sudo.

<quote>
Absolutely, repeatedly, in capital letters: DON'T!

Sudo is how you give a command permission to overwrite any
file, change any setting, remove any obstacle, destroy any
configuration, and do it without further confirmation. It's
similar to editing the Windows registry with a flamethrower.

You need those admin privileges to install routine system
updates (which you should be doing already) and programs
from Ubuntu Software Center / Synaptic, because those are
system-level changes. Those are perfectly fine, because
they're set up to work within the Ubuntu structure and have
been vetted by Folks Who Know. The installations are
automatic and, in principle and largely in practice, nothing
can go wrong.

*Any* other use of admin privileges, where you feed in your
password to allow a program or command to do something, is
fraught with peril. In particular, installing software that
wasn't set up for Ubuntu can cause terrible problems. This
isn't common, because (most likely) the install process will
fail, but sudo-ing around trying to make it work can't
possibly have a good outcome.

That's why Unix-style operating systems are so secure: you
can't damage the thing from a user account. But when a user
take on system-level privileges, anything is possible.
</quote>

Daniel B. Martin
 
Old 04-08-2010, 09:31 PM   #18
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Quote:
Originally Posted by danielbmartin View Post
You need those admin privileges to install routine system
updates (which you should be doing already) and programs
from Ubuntu Software Center / Synaptic, because those are
system-level changes. Those are perfectly fine, because
they're set up to work within the Ubuntu structure and have
been vetted by Folks Who Know. The installations are
automatic and, in principle and largely in practice, nothing
can go wrong.
By and large I can happily accept most of what he said.

What he didn't mention here is that "Ubuntu Software Center /
Synaptic"
are mere graphical front-ends for the apt
mechanisms, and that using
"sudo apt-get oorexx" is equivalent to firing up
synaptic, hunting the program down via a search, selecting
it with the rodent and clicking "Apply changes" (or however
it goes - I don't do Ubuntu, and haven't touched synaptic
in about 1.5 years).

So the problem above was twofold:
#1) he didn't (and probably couldn't, unless he has
endless time and energy) list all the possibilities
that make use of sudo acceptable.
#2) you took the "word of the law" for its spirit.

What interesting kinds of conversations at times arise
from completely harmless and technical questions. ;}

Hope you're not taking offense with my posts, no disrespect
intended at all.



Cheers,
Tink
 
Old 04-08-2010, 11:41 PM   #19
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,517

Rep: Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896
Hey Daniel

Quote:
That's a rather uncharitable accusation.
Sorry if this is how I made you feel, it was not my intent.
My reply was based on:

Quote:
I was hoping that experienced Linux programmers knew of a clever coding for cut which would "take the last five" directly, without resorting to using rev. Apparently this is not do-able.
And what I was trying to point out (although now i see poorly) was that you are using a hammer to kill a fly.
Like so many tasks that you will eventually do in linux you will find there are a plethora of tools and some are definitely
more adept at handling particular tasks.
You are quite right to say:

Quote:
I'm reluctant to put somebody else's code in my program if I don't understand it.
And hence I would always suggest testing on either a sample set or even better a copy.
Also, with reference to:

Quote:
If I don't understand it, I won't be able to change or extend it.
I and many others are more than happy to explain our solutions if you find them confusing.
Also, with a little googling at your fingertips, there are excellent tutorials on the commands all the solutions
are using.

I hope you will continue to explore and ask questions
 
Old 04-09-2010, 03:09 PM   #20
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,150

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Quote:
Originally Posted by danielbmartin View Post
I never heard of FOSS REXX interpreters, and that's why I didn't use one, or try one. Is there good reason to think they are superior to Regina?

I know zero about Object Oriented programming, so an Object Oriented REXX interpreter would not be helpful.
O.K, a definition and a question:
  1. "FOSS" is a fairly standard abbreviation for "Free or Open Source Software," not a special "flavor" of REXX.
  2. Have you installed the Regina REXX interpreter? They do have a free download available for Linux.
I haven't used REXX for at least a quarter of a century, but, for what it's worth, ANSI published a standard (ANSI X3.274–1996 “Information Technology – Programming Language REXX”) for it. That implies that anyone can implement the standard if they so wish.

As to oorexx, you might find this informative. The "REXX Language Association" is, I believe, the same group that developed the ANSI standard. So, when they claim that it's a superset of REXX, and that it will run any (standard compliant) REXX program, they probably know that it will.
 
Old 04-09-2010, 03:35 PM   #21
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,099

Original Poster
Rep: Reputation: 288Reputation: 288Reputation: 288
> Have you installed the Regina REXX interpreter?
> They do have a free download available for Linux.

Yes, I installed the free download. Regina works well but lacks some "extras" which are part of Reginald. One example is the DO OVER construct. I found that useful and coded it at a time when I did not realise it was "extra" and also did not anticipate switching from Windows to Ubuntu.

A trivial example:
t.7 = 'seven'
t.11 = 'eleven'
do k over t
say k t.k
end

Daniel B. Martin
 
Old 04-10-2010, 07:41 AM   #22
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by danielbmartin View Post
I was looking for a clever coding
of the CUT command.
Understood but it is not possible. As already mentioned Linux has many tools of more or less suitability to do this job.

If I understand correctly [that you are effectively porting a Rexx (lovely language ) program to Linux and you do not want to do so by running Rexx on Linux] then it will be hard to do so by simply stringing together Linux utilities such as cut, tac, rev etc. It will be much easier to do using one of the programming languages available in Linux and use cut, tac, rev etc where appropriate.

As a learner it's easier to learn a minimal set of tools to get the job done and then expand your knowledge as interest and need arise. With this in mind (and awaiting many comments!) ... sed and awk are good tools for text processing so there's little point in learning both to begin with. If you know Rexx then awk will be the easier of the two because it is more of a programming language.

Linux shares UNIX' design concept of having many tools to do specific jobs (like cut, tac, rev etc.). This concept is only useful in conjunction with a command shell that can string such commands together (in a "pipeline") so the output of one can be used as the input to another and so on.

That means you do also need to use a language which can do this well; bash is the most widely used; many people recommend PERL.

You mention execution time. If this is important then you will want to use the built-in facilities of bash (or PERL). Each time they call an external program (like cut, tac, rev etc.) there is a fairly heavy overhead. One exception to this is handling large amounts of text; bash does this relatively slowly (PERL is a lot faster).

Unfortunately bash (and PERL) are un-intuitive languages so are not easy to learn in full but you can do useful things after learning a small part of the language and progress from there as you wish.

As an example of using bash only to solve your problem (and hoping you may be attracted sufficiently by its minimalism to look again at bash)
Code:
#!/bin/bash

while read first_word rest
do
    word_length=${#first_word}
    let index=word_length-5
    echo ${first_word:$index}
done < input.txt
Notes:
  1. The while loop continues as long as the read command succeeds.
  2. The read command reads a line at a time from "standard input". Standard input is taken from the input.txt file by done < input.txt.
  3. read first_word rest says "read the first word of the line into variable $first_word and the rest into variable $rest (which is not used).
  4. ${#first_word} is the length of the value of variable $first_word.
  5. The let command sets variable $index to the length of variable $first_word less 5.
  6. The echo command writes what follows it to "standard output". This is the terminal screen (it can be changed).
  7. ${first_word:$index} is the substring of $first_word, starting at position $index.
  8. This script does not work for first words that are less than 5 characters long (no insurance!). It could be modified to do so but I wanted to keep it simple.
 
Old 04-10-2010, 11:52 AM   #23
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,099

Original Poster
Rep: Reputation: 288Reputation: 288Reputation: 288
> You mention execution time. If this is important ...

Execution time was not the original subject of his thread but it is worth mentioning.

I started with a Reginald/Windows REXX program which generated the desired results. I had to do minor recoding to make it work as a Regina/Linux REXX program. Along the way, I discovered that I could replace large chunks of REXX code with smaller chunks of Linux commands.

Now we get to the punch line, and that is execution time.
Same input file, 500,000+ records.
Same output file, 220,000+ records.
Execution time for the original REXX-only version: 9+ hours.
Execution time for the new mixed REXX+Linux version: 1 minute.
A breathtaking improvement! As a consequence, execution time for this program is now of small concern.

This dramatic reduction in execution time provides the motivation to learn more Linux commands and rework more of my REXX-only programs.

Daniel B. Martin
 
Old 04-10-2010, 01:06 PM   #24
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by danielbmartin View Post
Now we get to the punch line, and that is execution time.
Same input file, 500,000+ records.
Same output file, 220,000+ records.
Execution time for the original REXX-only version: 9+ hours.
Execution time for the new mixed REXX+Linux version: 1 minute.
A breathtaking improvement!
Breathtaking? That's huge! And somewhat surprising because Rexx and bash inhabit similar worlds (I learned C and UNIX by writing a Rexx interpreter -- a stalled project that will probably never see the light of day but it was a great way to learn). As I recall the big overhead was having to provide Rexx's trace functionality and bash does much the same using set -xv.
 
Old 04-11-2010, 04:40 PM   #25
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,150

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Returning to oorexx, your example program (with a slight change) works fine using it:
Code:
$ cat test
t.7 = 'seven'
t.11 = 'eleven'
do k over t.
say k t.k
end
$ rexx test
11 eleven
7 seven
(The "slight change" is the period following the "t" in the "do over" directive.)
 
  


Reply

Tags
efficiency, execution, time


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] awk: how to print a field when field position is unknown? elfoozo Programming 12 08-18-2010 03:52 AM
awk printing from Nth field to last field sebelk Programming 2 01-08-2010 09:39 AM
LXer: Mastering Characters Sets in Linux (Weird Characters, part 2) LXer Syndicated Linux News 0 11-25-2009 11:30 PM
php question, how do I get a return from a field within a field? cherrington Programming 11 04-29-2009 01:27 AM
How to overwrite/change characters in the same field with C. slzckboy Programming 6 05-23-2005 05:07 PM


All times are GMT -5. The time now is 11:27 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration