I've the CSS file with many entry like
#id1, #id2, #id3, #id4 { ... }
#id3, #id2 { ... }
#id2, #id4 { ... }
I want to extract list of unique IDs using command line tools (msys). Unique means any开发者_开发技巧 entry in list presented only once. How?
PS: I know how doing it using python, but what about awk/sed/cat?
Try this
cat file.css | grep -o '#[a-zA-Z0-9-]*' | sort -u
Edit: unfortunately, this regexp is very crude and will allow hex colors to pass as IDs..
If css in your files are such that opening { is ALWAYS on the same line with #ids, then you an use this syntax:
cat file.css | grep { | cut -d'{' -f1| grep -o '#[a-zA-Z0-9-]*' | sort -u
In awk it may be easier:
awk -F'[,[:space:]]' -v RS=# 'NF{if (!a[$1]++) print $1}' file.css
though this code doesn't check for the presence of '{ ... }'.
精彩评论