How to replace a certain fonts name in the css file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace a certain fonts name in the css file?
# 1  
Old 05-20-2011
How to replace a certain fonts name in the css file?

Hi,

I have a *.css file which has so many attributes, one of them is "font-family".

This font-family has certain fonts like Helvetica, Lucida grande, Arial, sans-serif, Monaco etc., Now I want to replace all these font names other than "Arial" (i.e except Arial) to "Arial".

So, I want a regular expression to replace the font name to "Arial" where ever the "font-family" line comes, for eg:

Code:
font-family: Helvetica, sans-serif, Arial;

to
Code:
font-family: Arial, Arial, Arial;

Keeping the space, comma everything intact

There are many such occurrences of font-family in the css file that I want to replace globally and the fonts count differs, in some places just 2 font names, in other places it will be four etc.,
# 2  
Old 05-20-2011
try this,
Code:
awk -F"[:,]" '{if(/^font-family/){printf $1":";for(i=2;i<=NF;i++) {if($i != "Arial"){printf i==NF?" Arial;\n":" Arial,"}}}else{print}}' inputfile

This User Gave Thanks to pravin27 For This Post:
# 3  
Old 05-20-2011
Code:
sed '/font-family:/s/[A-Z a-z-]*,/ Arial,/g' infile

# 4  
Old 05-23-2011
Quote:
Originally Posted by ygemici
Code:
sed '/font-family:/s/[A-Z a-z-]*,/ Arial,/g' infile

Thanks, but this fails, for the font at the end.
# 5  
Old 05-23-2011
Quote:
Originally Posted by royalibrahim
Thanks, but this fails, for the font at the end.
Where is the wrong?
Code:
# echo "font-family: Helvetica, sans-serif, Arial;"|sed '/font-family:/s/[A-Z a-z-]*,/ Arial,/g'
font-family: Arial, Arial, Arial;

Code:
# echo "font-family: Helvetica, sans-serif, Arial;"|awk -F"[:,]" '{if(/^font-family/){printf $1":";for(i=2;i<=NF;i++) {if($i != "Arial"){printf i==NF?" Arial;\n":" Arial,"}}}else{print}}'
font-family: Arial, Arial, Arial;

# 6  
Old 05-23-2011
Quote:
Originally Posted by ygemici
Where is the wrong?
Code:
# echo "font-family: Helvetica, sans-serif, Arial;"|sed '/font-family:/s/[A-Z a-z-]*,/ Arial,/g'
font-family: Arial, Arial, Arial;

Can you please check the code against this file?

Code:
font-family: Helvetica, verdana, Arial;
font-family: Bodoni, arial, Webdings, Sans-serif, arial;
font-family: Lucida Console, Arial, Gothic;
font-family: arial
font-family: arial, Vivaldi;

# 7  
Old 05-23-2011
Quote:
Originally Posted by royalibrahim
Can you please check the code against this file?

Code:
font-family: Helvetica, verdana, Arial;
font-family: Bodoni, arial, Webdings, Sans-serif, arial;
font-family: Lucida Console, Arial, Gothic;
font-family: arial
font-family: arial, Vivaldi;

ok use this
Code:
sed '/font-family:/s/ [A-Z a-z-]*/ Arial/g;/;$/!s/$/;/' file1

Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Web Development

Optimizing JS and CSS

Yes. Got few suggestions. - How about minifying resources - mod_expires - Service workers setup https://www.unix.com/attachments/web-programming/7709d1550557731-sneak-preview-new-unix-com-usercp-vuejs-demo-screenshot-png (8 Replies)
Discussion started by: Akshay Hegde
8 Replies

2. Web Development

CSS frameworks

I have been reading up on CSS frameworks, to see if it could be useful for an intranet that I am helping to build, but the true purpose does not become clear to me. What circumstances would the deployment of a CSS framework be useful in? What does a CSS framework do that a CMS template cannot do? (1 Reply)
Discussion started by: figaro
1 Replies

3. Web Development

HTML down, CSS help, ahhhh

I am having some problems. I have been able to learn HTML, but when I try and encode CSS, nothing happens, what is the major issue here. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>MY CSS</title> <style... (7 Replies)
Discussion started by: N-Training
7 Replies

4. Web Development

On Css

<html> <head> <style> div.box {width: 300px; height: 200px; padding: 30px; font: 46 pt times new roman;} </style> </head> <body> <div class="box" style=" filter": progid:DXImagetransform.Microsoft.Alpha (Opacity=100, FinishOpacity=0, Style=1, StartX=0, FinishX=0,... (0 Replies)
Discussion started by: N-Training
0 Replies

5. UNIX for Dummies Questions & Answers

CSS coding conventions checker

I would like to use an automated checker for adherence to CSS coding conventions. I have browsed the web, but no tool I came across checks for coding conventions, only syntax. Here is a general list of requirements: - Style definitions should be separated by one blank line - Indentation is 2... (0 Replies)
Discussion started by: figaro
0 Replies
Login or Register to Ask a Question