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 02-11-2010, 09:43 PM   #1
phenomenix
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Rep: Reputation: 0
understanding 1,p$ construction in ed


OK, I'm truly a a newbie. I'm in a Linux class at a community college with the worlds worst instructor and a worthless textbook.

The book starts using the following ed construction:
1,$p 'Print all the lines'
but it doesn't give a clue about what the parts of this construction means. I asked the instructor and he gave me an obviously wrong answer about it putting it in a registry. I know he's confused. This guy knows zero linux.

I understand that the p is for print. I take it from the book that the $ means end of a line.

I have no idea what the 1 means or how the syntax of this line works. Since I gather that ed is a line editor I think it should only print one line anyway, but the "explanation" clearly says "print ALL the lines."

Google is no help, since it doesn't recognize symbols such as , and $.

Can anyone help me?

Roger
 
Old 02-11-2010, 09:58 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,434

Rep: Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790
well, I'm surprised you're using 'ed' that's a precursor to vi (precursor to vim).
anyway, it looks like the vi/vim cmd

:1,$p

You get the ':' when in cmd mode (you can use ed-like constructions); meaning is

1 - start from first line
, - range marker
$ - to last line
p - print line

therefore, print all lines from 1 to $ (ie last line = end of file)

HTH
http://www.vim.org/
 
Old 02-11-2010, 10:04 PM   #3
phenomenix
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you

Thank you Chris.

Actually we're not using ed, we're using sed to learn about regular expressions, but this "beginners" book starts the chapter by saying "Throughout this section we assume familiarity with a line-based editor such as ex or ed."

Of course, that's the first reference to any such thing, and it stopped me dead in my tracks right there.

Anyway - enough blowing off steam. Thanks for your help.

Roger
 
Old 02-11-2010, 10:12 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
1 is line 1, $ is the last line, so 1,$p means "for line = 1 .. last_line; print line"

Note that this is an ed construction, and ed is a very seldom used Linux editor. ed is a great editor if you are using a real tty to edit a file, where your input and output is printed on paper. Most system in use today use CRT display systems, where the screen can be re-displayed to reflect changes, and - on a simple CRT display (one without a Graphical User Interface, a "GUI") an editor like nano or vi is much more common.

About the only current use of ed-like commands is in old programs (like mail and sed) ported from 1980s UNIX systems, and used, almost exclusively, by system administrators.

Of course, almost all current Linux distributions are shiped wit a GUI, and include several full-screen WYSIWUG (What You See Is What You Get) editors. While learning ed might be of interest to a historian, I can't see much point in including it in a Linux class.

(And, just FYI, no Linux system of which I'm aware has anything like a "registry." Most system and application control files in a Linux system are in the /etc directory, and they are simple, easily read, text files.)

Last edited by PTrenholme; 02-12-2010 at 12:57 PM.
 
Old 02-11-2010, 10:23 PM   #5
phenomenix
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Registry meant register

I'm pretty sure he meant register, as in the construction
^\(.\).*\1$
where the result is places in a "register"

He just can't talk. Kinda like his constant use of the word "apprehend" to mean append.
 
Old 02-11-2010, 11:01 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,434

Rep: Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790
apprehend = append a policeman to a criminal


BTW agree with PTrenholme. The main editor to at least know the basics of is vi; its installed by default on just about any/all versions of *nix, inc Linux, *BSD, AIX, Solaris, HP-UX, Mac-OSX (I believe).
The minimal recovery shell ash includes a cut-down version of vi built-in.
Also, very low overhead for low bandwidth cxns.
 
  


Reply


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
Ksimus construction a_c_g_t SUSE / openSUSE 0 04-08-2007 02:27 PM
Message Construction ranjeet_badhe Linux - Software 1 05-30-2006 01:59 PM
my website appears under construction nasim2 Linux - Newbie 4 02-09-2006 04:49 PM
web site under construction nasim2 Linux - General 2 02-09-2006 09:01 AM
Setting up a block, for this area is under construction. Thrifty Linux - Software 3 04-21-2004 09:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration