1

I would like to extract css comments from style.css.

Comments are in the beginning of the css files and they are formatted like this

/*
Author:name
URI:link
etc
*/

After some searches I found :

sed -n '/^\/\*\$,/\*\/$/p' style.css

It didn't work, I had this error :

sed: -e expression #1, char 11: unknown command: `\'

Do you suggest a good solution.

If possible with a good link for a tutorial for basic sed uses for beginners.

3 Answers 3

2

This sed should work:

sed -n '/\/\*/,/\*\//{P;/\*\//q;D;}' style.css
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks,it works, but I just need the first bloc between /* and */, your suggestion will show all the blocs. What should I add then ?
Your expression works,thanks. I am just trying to remove patterns /* and */ from the result, I was thinking that -n is enough but no, the patterns shows in the final result. I think I should add another sed to substitute them with blank.
I added | sed '1d;$d'
sed -n '/\/\*/,/\*\//{/\*\//q;/\/\*/!P;D;}' style.css would also work same way.
1

I think you mean:

sed -n '/^\/\*$/,/\*\/$/p' style.css

You had $ and / in the first regep backwards.

4 Comments

Yes I think I forgot / , but executing this will show nothing.
It is weird that this sed -n '/^\/\*\$/,/\*\/$/p' style.css will not show anything
That's not the same as my answer, you have \ before $, which makes it a literal instead of matching the end of line.
Maybe your actual file has spaces after /* or */.
0

If they are always in a colon delimited format like that, you can use:-

sed -n '/Author/p' | cut -d':' -f2

That will get you the author name. I'd definitely recommend learning about cut for colon delimited files.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.