LinuxQuestions.org
Review your favorite Linux distribution.
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 05-17-2005, 12:45 PM   #1
benobi
LQ Newbie
 
Registered: May 2004
Posts: 18

Rep: Reputation: 0
sed


I'm trying to understand these sed rules I found in a makefile, can anyone tell me if I'm reading them correctly?

Code:
sed -e 's/#.*//'
says, substitute #.* with blanks.

Code:
sed -e 's/^[^:]*: *//'
This one eludes me. I know ^ matches a character at the beginning of a line. So I think the first half says, substitute any character that isn't a colon that appears at the beginning of a line. But then what's the *: * part that follows it?

Code:
sed -e 's/ *\\$$//'
Not sure about this one either. I think this says to substitute the text string "*\\$$" with nothing?

Code:
sed -e '/^$$/ d'
Delete each line that begins with $$ string?

Code:
sed -e 's/$$/ :/'
I'm thinking: Substitute a $ character at the end of a line with a :
 
Old 05-17-2005, 01:49 PM   #2
cathectic
Member
 
Registered: Sep 2004
Location: UK, Europe
Distribution: Slackware64
Posts: 761

Rep: Reputation: 35
From http://www.amk.ca/python/howto/regex...metacharacters:
Quote:
$
Matches at the end of a line, which is defined as either the end of the string, or any location followed by a newline character.
 
Old 05-17-2005, 01:53 PM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
Quote:
I found in a makefile
Sounds more like a make homework file
Anyway keep plugging away at it, you aren't doing too bad.
 
Old 05-17-2005, 02:00 PM   #4
benobi
LQ Newbie
 
Registered: May 2004
Posts: 18

Original Poster
Rep: Reputation: 0
It's not my homework... My friend told me to look at this makefile for this program someone else wrote and I can't seem to figure it out. If $ is end of line why are there two $'s in a row? Does that mean the end of the end of a line? What about ^$? Does this mean beginning of the end of the line?
 
Old 05-17-2005, 02:22 PM   #5
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
Ok, so what I do is create a small file.txt with examples in it and then run the code to see what it does. For example...
file.txt
Code:
now is the time
$
$$
for all good
men to come to
the aid of thier
Code:
cat file.txt | sed -e '/^$$/ d'
now is the time
$$
for all good
men to come to
the aid of thier
So what that does is remove the line which starts ( ^ ) and ends ( $ ) with a $
 
Old 05-17-2005, 02:48 PM   #6
benobi
LQ Newbie
 
Registered: May 2004
Posts: 18

Original Poster
Rep: Reputation: 0
Oh ok, how come the $$ line didn't get deleted? It starts with a $ and ends with a $.
 
Old 05-17-2005, 03:04 PM   #7
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
The first line only had one $ and that is what the sed was told to look for.
If you want more than one of something, you would use a *
For example...
Code:
cat file.txt | sed -e '/^$*$/ d'
Now this example looks for a line which has a # in it and replaces the area from the # on with a blank.
If the # happens at the beginning of the line, you get a blank line.
Code:
cat file.txt | sed -e 's/#.*//'
 
Old 05-17-2005, 03:23 PM   #8
benobi
LQ Newbie
 
Registered: May 2004
Posts: 18

Original Poster
Rep: Reputation: 0
Ok i understand $*$ and #.* now.

I'm still having trouble grasping ^$$

I have this in a text file:
Code:
$hello
$hello$
hello$
$$hello
and i run:
Code:
cat temp.txt | sed -e 's/^$$//'
and i get:
Code:
$hello
$hello$
hello$
$$hello
How come none of those got removed?
 
Old 05-17-2005, 03:44 PM   #9
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
cat temp.txt | sed -e 's/^$$//' is looking for a line that only has one $ and nothing else
 
  


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
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Sed q? ky-lab_rat Linux - Software 5 10-26-2004 07:59 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
Help with sed odious1 Linux - General 2 08-29-2003 10:52 AM
help with sed DavidPhillips Programming 3 08-11-2003 04:46 PM

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

All times are GMT -5. The time now is 07:10 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration