trying to understand what sed is doing?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting trying to understand what sed is doing?
# 1  
Old 06-29-2009
trying to understand what sed is doing?

Can someone help me understand why

sed '/host/ s/$/QQQ/g' junk

is taking the file 'junk' which is this:

host Example_1
filename-"gfnwd.cfg";
hardware-ethernet-00:13:11:fd:7a:88;
fixed-address-10.10.6.19;
}
host Example_2
filename-"gfnwd_280.cfg";
hardware-ethernet-00:10:3d:14:30:ce;
fixed-address-10.10.6.59;
}
host Example_13
filename-"robnmic1.cfg";
hardware-ethernet-00:10:3d:12:9e:c8;
fixed-address-10.10.3.30;
}


and doing this:


QQQost Example_1
filename-"gfnwd.cfg";
hardware-ethernet-00:13:11:fd:7a:88;
fixed-address-10.10.6.19;
}
QQQost Example_2
filename-"gfnwd_280.cfg";
hardware-ethernet-00:10:3d:14:30:ce;
fixed-address-10.10.6.59;
}
QQQost Example_13
filename-"robnmic1.cfg";
hardware-ethernet-00:10:3d:12:9e:c8;
fixed-address-10.10.3.30;

What I'm trying to do is for every line that contains "host" append at the end of the line "QQQ". I thought that is what the $ means.

Any help would be appreciated.
# 2  
Old 06-29-2009
Works for me, try again.
# 3  
Old 06-29-2009
kubuntu@kubuntu-M6400:/$ sed '/host/ s/$/QQQ/g' junk
QQQost Example_1
filename-"gfnwd.cfg";
hardware-ethernet-00:13:11:fd:7a:88;
fixed-address-10.10.6.19;
}
QQQost Example_2
filename-"gfnwd_280.cfg";
hardware-ethernet-00:10:3d:14:30:ce;
fixed-address-10.10.6.59;
}
QQQost Example_13
filename-"robnmic1.cfg";
hardware-ethernet-00:10:3d:12:9e:c8;
fixed-address-10.10.3.30;
}
kubuntu@kubuntu-M6400:/$

I'm using Kubuntu 9.04 with sed version 4.1.5.

---------- Post updated at 12:07 PM ---------- Previous update was at 11:45 AM ----------

VERY Strange!!

I loaded a Fedora 11 box and did the same command. Works fine... It's starting to look like a Kubuntu bug...

Last edited by TheBigAmbulance; 06-29-2009 at 03:26 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help me understand this script

#!/bin/awk -f BEGIN {i=1;file="modified.txt"} { if ($0 !~ /^DS:/) {print $0 >> file} else { if ($0 ~ /^DS:/) {print "DS: ",i >> file;if (i==8) {i=1} else {i++}}; } } END {gzip file} Can someone explain to me how this above script works, I got it from a friend but not able... (3 Replies)
Discussion started by: Kamesh G
3 Replies

2. Shell Programming and Scripting

understand sed

cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit chowdury 26688726 If i use the below command , it is giving me the output with "," in between two name. how ? and also i would like to know the reason for the space used in... (1 Reply)
Discussion started by: Antony Ankrose
1 Replies

3. Shell Programming and Scripting

I am learning regular expression in sed,Please help me understand the use curly bracket in sed,

I am learning SED and just following the shell scripting book, i have trouble understanding the grep and sed statement, Question : 1 __________ /opt/oracle/work/antony>cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit... (7 Replies)
Discussion started by: Antony Ankrose
7 Replies

4. Shell Programming and Scripting

can't understand!

Hi All, can you please help me to figured out what's the meaning of this. ${SERVER_DATABASE} -b << EOF 2>>/dev/null THanks, (3 Replies)
Discussion started by: nikki1200
3 Replies

5. Shell Programming and Scripting

I can't understand sed error output.

Hey forum, I have a problem with a script what used to work, but suddenly is not working anymore. I have been trying different things for an hour now and I give up :D . #!/bin/sh asukoht=`pwd` template=$1 for values in... (4 Replies)
Discussion started by: mario8eren
4 Replies

6. Shell Programming and Scripting

Can't understand the script

I am relatively new to Shell Scripting. I can't understand the following two scripts. Can someone please spare a minute to explain? 1) content s of file a are (021) 654-1234 sed 's/(//g;s/)//g;s/ /-/g' a 021-654-1234 2)cut -d: -f1,3,7 /etc/passwd |sort -t: +1n gives error (3 Replies)
Discussion started by: shahdharmit
3 Replies

7. Shell Programming and Scripting

Sed command - help me understand

Hello, can someone please explain me what the following commands do.. i know the output but i would like to understand the break down of what they do step by step. 1) sed -n "/ $(date +\%R -d "-1 min")/,$"p req.txt| wc -l 2) awk '/19:00/,/22:00/' app.log |grep "mytesturl"|grep... (2 Replies)
Discussion started by: niks
2 Replies

8. UNIX for Dummies Questions & Answers

can't understand this at all.

Ok, i've been trying to write some shell scripts. nothing challenging, but just automating All of the tutorials i read say to start the file with #!/bin/bash or whatever your path to bash is. So i do it, and all of my scripts error out saying ./nameofscript:command not found when i... (4 Replies)
Discussion started by: severndigital
4 Replies

9. UNIX for Dummies Questions & Answers

can't understand

how i can download this game n start it :S (5 Replies)
Discussion started by: BoyArcher
5 Replies
Login or Register to Ask a Question