sed no match word end with hyphen


 
Thread Tools Search this Thread
Top Forums Programming sed no match word end with hyphen
# 1  
Old 02-25-2011
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:
Code:
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
Code:
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 :-)
# 2  
Old 02-26-2011
Quote:
Originally Posted by medium_linux
...
My problem is to not include words with hyphen in the match!
...
But your desired output does include words with hyphen!
As can be seen here -

Quote:
Originally Posted by medium_linux
... I would like this output if possible
Code:
grep height file2:
height: 40px;
    line-height: 1.5em;
    height: 40px;
    height: 40px;
    height: 40px;
    line-height: 17px;

...
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
This User Gave Thanks to durden_tyler For This Post:
# 3  
Old 02-26-2011
for 1
Code:
sed -n '/^ [^-].*height/p' file1>file2

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

This User Gave Thanks to yinyuemi For This Post:
# 4  
Old 02-26-2011
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
Code:
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! Smilie

Last edited by Scott; 02-26-2011 at 07:59 AM.. Reason: Code tags
# 5  
Old 02-26-2011
Code:
$ 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;

This User Gave Thanks to kurumi For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed script to delete the last word after a last pattern match

Hi Guys , I am having a file as stated below File 1 sa0 -- i_core/i_core_apb/i_afe0_controller/U261/A sa0 -- i_core/i_core_apb/i_afe0_controller/U265/Z sa1 -- i_core/i_core_apb/i_afe0_controller/U265/A sa1 -- i_core/i_core_apb/i_afe0_controller/U268/Z sa1 -- ... (7 Replies)
Discussion started by: kshitij
7 Replies

2. Shell Programming and Scripting

sed command to append word at end of line

hello Team, I am looking for sed command or script which will append word at end of line. for example. I want to validate particular filesystem with mount |<filesystem name> command. if nodev parameter is not there then it should add in the fstab file with receptive to the filesystem. # mount... (8 Replies)
Discussion started by: ghpradeep
8 Replies

3. Shell Programming and Scripting

sed print from last occurrence match until the end of last occurrence match

Hi, i have file file.txt with data like: START 03:11:30 a 03:11:40 b END START 03:13:30 eee 03:13:35 fff END jjjjjjjjjjjjjjjjjjjjj START 03:14:30 eee 03:15:30 fff END ggggggggggg iiiiiiiiiiiiiiiiiiiiiiiii I want the below output START (13 Replies)
Discussion started by: Jyotshna
13 Replies

4. Shell Programming and Scripting

Insert a hyphen between two delimiters using sed

Hey guys, I have a file that is delimited by | and I am trying to write a sed command to convert this: abc|def||ghi|jkl||||mnop into this: abc|def|-|ghi|jkl|-|-|-|mnop The output I am getting out of: sed -e "s/+//g" /tmp/opt.del > /tmp/opt2.del is like: ... (9 Replies)
Discussion started by: prohank
9 Replies

5. Shell Programming and Scripting

Search from 1st match and end 2nd match

I've been looking through the forums for awhile now and looking at the man page for grep and egrep and not seeming to find this scenario so it might not be possible but figured I'd throw it out to get some ideas. I'm looking for a way to search a file for 1st match (example below net self) and... (3 Replies)
Discussion started by: djzah
3 Replies

6. Shell Programming and Scripting

sed - replacing a substring containing a hyphen

I'm attempting to replace a substring that contains a hyphen and not having much success, can anyone point out where i'm going wrong or suggest an alternative. # echo /var/lib/libvirt/images/vm888b-clone.qcow | sed -e 's|vm888-clone|qaz|g' /var/lib/libvirt/images/vm888b-clone.qcow (1 Reply)
Discussion started by: squrcles
1 Replies

7. Shell Programming and Scripting

Removing hyphen from beginning and end of a word only.

It is very simple to remove a hyphen from a word anywhere in that word using a simple sed command (sed -i 's/-//g' filename), but I am not able to figure out how to do this: For example, apple -orange tree pipe- banana-shake dupe- What my output should look like: apple orange tree... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

8. Shell Programming and Scripting

sed - extracting the first word only if match

Hello. from a text file, I want to get only the first word ( before blank ) following code= grep -i -e "WORD1" "/path/to/text/file.txt | sed -n 's/WORD1\+//p' | sed -n 's/code=/\1/p' return an error. sed: -e expression #1, char 12: invalid reference \1 on `s' command's RHSFor debugging... (12 Replies)
Discussion started by: jcdole
12 Replies

9. Shell Programming and Scripting

sed print from last occurrence match until the end of file

Hi, i have file f1.txt with data like: CHECK a b CHECK c d CHECK e f JOB_START .... I want to match the last occurrence of 'CHECK' until the end of the file. I can use awk: awk '/^CHECK/ { buf = "" } { buf = buf "\n" $0 } END { print buf }' f1.txt | tail +2Is there a cleaner way of... (2 Replies)
Discussion started by: ysrini
2 Replies

10. Shell Programming and Scripting

Sed : identify a pattern and append a word at the end of a line

Hello to all, On aix, I want to identify a term on a line in a file and then add a word at the end of the line identified. I do not want the word to be added when the line contains the symbol "#". I use the following command, but it deletes the term identified then adds the word. #sed... (4 Replies)
Discussion started by: dantares
4 Replies
Login or Register to Ask a Question