sed no match word end with hyphen

Hi,
This is my first post.It has two parts
first part:
I want to match a line that starts with whitespace tab or similar followed by
must start with specific word and not match same word start with hyphen
like this:

grep height file1:
    height: 150px;
    line-height: 1.5em;
    height: 100px;
    height: 350px;
    height: 100px;
    line-height: 17px;

second part
I would like to redirect content to another file and the word that matches (in this case height ) I would like to set a fix value like (height: 40px; for every height value.
And after this is done I would like this output if possible

grep height file2:
height: 40px;
    line-height: 1.5em;
    height: 40px;
    height: 40px;
    height: 40px;
    line-height: 17px;

I understand the basic about sed. My problem is to not include words with hyphen in the match!
Is it possible to do with sed, or do you have any better approach?

Help would be deeply appreciated :slight_smile:

But your desired output does include words with hyphen!
As can be seen here -

So do you want to display lines that have "-height" or not ?
Do the following:

(a) Post a sample input file.
(b) Post the desired output that you want from your sample input file.

That should help clear things up.

tyler_durden

1 Like

for 1

sed -n '/^ [^-].*height/p' file1>file2

for 2

awk '/[^-]height/{sub(/[0-9]*px/,"40px")}1' file2
1 Like

Thank You!
Sorry for being unclear!
What I wanted to do, is change a style.css file by modify only specific lines in the file

sed -n '/^ [^-]*height/p' file1>file2 #without dot worked

awk '/[^-]height/{sub(/[0-9]*px/,"40px")}1' file2 # Very elegant solution. Did exactly what I wanted.

Thank You very much! :slight_smile:

$ ruby -pne '$_.gsub!(/\d+px/,"40px")  if /^\s+height/ && !$_["-"]' file
    height: 40px;
    line-height: 1.5em;
    height: 40px;
    height: 40px;
    height: 40px;
    line-height: 17px;

1 Like