Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 26 Jul 2014, 05:08
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
head buried in sed
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 2 [21 Posts]   Goto page: Previous 1, 2
Author Message
8-bit


Joined: 03 Apr 2007
Posts: 3355
Location: Oregon

PostPosted: Wed 13 Jan 2010, 03:03    Post subject:  

Did you notice I said section and not line?
A section of code in a program would be commented as to what you expect it to do.
There is no advantage to commenting lines.
Also a line that tries to combine a lot is not my idea of fun.
Especially when it comes to debugging.
I try to keep from combining a bunch of actions on one line.
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7782
Location: qld

PostPosted: Wed 13 Jan 2010, 05:29    Post subject: Re: Comments  

prehistoric wrote:
The trick is to make them (comments) an aid to development, and write them first. Write pseudo-code to be executed by the human who writes the detailed code, even if this is yourself.


Lately that is how I have been planning a script. Write the comments into a logical order then write the code, specially if there is something new I've learned and may not revisit for awhile.

My current sig aroused some interest...


Quote:
You may have understood the script perfectly when you wrote it. But six months from now it could look like modem noise.
Bruce Barnett (I put here for future ref, I will eventually change my sig again Wink )

Good healthy discussion on comments and when/how to use them. Still learning, and it's not all about code. Smile

eg
Code:
#need something to append "&" to every line
sed -i 's/$/ \&/' /path/to/file


Cheers

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
aragon

Joined: 15 Oct 2007
Posts: 1698
Location: Germany

PostPosted: Wed 13 Jan 2010, 09:38    Post subject:  

technosaurus wrote:
I never could figure out how to easily replace an existing "new line" \n with a different character |,\t(tab) .... probably because it is a LINE editor and that would make it a lineS editor.

tr does a good job for this kind e.g.

Code:
tr "\n" "NEWCHAR"


aragon

_________________
PUPPY SEARCH: http://wellminded.com/puppy/pupsearch.html
Back to top
View user's profile Send private message 
bill

Joined: 28 May 2008
Posts: 492

PostPosted: Thu 14 Jan 2010, 12:11    Post subject: remarks and comments in code etc.  

Just my two cents but I see it like Prehistoric,and I think remarks are not only for the original programmer but for anyone whom you may share your work with.Isn't this what Puppy is all about ? I'm thinking also that remarks can help some kind soul who wishes to lend a hand on something you may not be able to get quite right.I know this is old school thinking and I certainly fit that category.(old) Confused cheers
Back to top
View user's profile Send private message 
DMcCunney

Joined: 02 Feb 2009
Posts: 897

PostPosted: Tue 26 Jan 2010, 20:36    Post subject: Re: head buried in sed
Subject description: sed options
 

01micko wrote:

Now in zigbert's code the suffix is usually "e"... "e" is another sed option but I am not sure of how this works. Until I do know how this works I am leaving the e out of my code.

Any body know about this one?

sed is the Unix "stream editor", intended to be used in scripts to make unattended edits on files.

By default, sed expects to be used in "one liners", where you issue the sed command, the editing commands, and the file(s) you want sed to process on the command line. This is fine for simple edits, but some things you want to do may be more extensive. and require multi-line sed scripts read from an external file.

That's what -e is for. After "sed -e", sed expects the name of an editing script, like "sed -e foobar.sed <input file>"

sed offers the full range of editing features of the ed line editor, including regular expressions and branching operations. When you run sed on a file, sed reads each line of the input file in turn and runs the editing script on it, then writes out the line and reads the next.

When it has processed all lines in the file, sed exits, and control passes to whatever called it.

.The canonical home for sed is on SourceForge, and much good information may be found there: http://sed.sourceforge.net/
______
Dennis
Back to top
View user's profile Send private message 
DMcCunney

Joined: 02 Feb 2009
Posts: 897

PostPosted: Tue 26 Jan 2010, 20:46    Post subject:  

technosaurus wrote:
I never could figure out how to easily replace an existing "new line" \n with a different character |,\t(tab) .... probably because it is a LINE editor and that would make it a lineS editor.

It is a lineS editor. Run sed on a file, and it reads each line of the file and runs the edit commands/script you passed to it on the line, then reads the next. When it's processed all lines, it exists.

As for changing line endings:
Code:
TEXT CONVERSION AND SUBSTITUTION:

 # IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format.
 sed 's/.$//'               # assumes that all lines end with CR/LF
 sed 's/^M$//'              # in bash/tcsh, press Ctrl-V then Ctrl-M
 sed 's/\x0D$//'            # works on ssed, gsed 3.02.80 or higher

 # IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format.
 sed "s/$/`echo -e \\\r`/"            # command line under ksh
 sed 's/$'"/`echo \\\r`/"             # command line under bash
 sed "s/$/`echo \\\r`/"               # command line under zsh
 sed 's/$/\r/'                        # gsed 3.02.80 or higher

 # IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format.
 sed "s/$//"                          # method 1
 sed -n p                             # method 2

 # IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format.
 # Can only be done with UnxUtils sed, version 4.0.7 or higher. The
 # UnxUtils version can be identified by the custom "--text" switch
 # which appears when you use the "--help" switch. Otherwise, changing
 # DOS newlines to Unix newlines cannot be done with sed in a DOS
 # environment. Use "tr" instead.
 sed "s/\r//" infile >outfile         # UnxUtils sed v4.0.7 or higher
 tr -d \r <infile >outfile            # GNU tr version 1.22 or higher

from http://sed.sourceforge.net/sed1line.txt
______
Dennis
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 2 of 2 [21 Posts]   Goto page: Previous 1, 2
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0702s ][ Queries: 12 (0.0095s) ][ GZIP on ]