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/#.*//' Code:
sed -e 's/^[^:]*: *//' Code:
sed -e 's/ *\\$$//' Code:
sed -e '/^$$/ d' Code:
sed -e 's/$$/ :/' |
From http://www.amk.ca/python/howto/regex...metacharacters:
Quote:
|
Quote:
Anyway keep plugging away at it, you aren't doing too bad. |
It's not my homework... :p 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?
|
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 Code:
cat file.txt | sed -e '/^$$/ d' |
Oh ok, how come the $$ line didn't get deleted? It starts with a $ and ends with a $.
|
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' If the # happens at the beginning of the line, you get a blank line. Code:
cat file.txt | sed -e 's/#.*//' |
Ok i understand $*$ and #.* now.
I'm still having trouble grasping ^$$ I have this in a text file: Code:
$hello Code:
cat temp.txt | sed -e 's/^$$//' Code:
$hello |
cat temp.txt | sed -e 's/^$$//' is looking for a line that only has one $ and nothing else
|
All times are GMT -5. The time now is 12:31 PM. |