| |
| |
| |
|
Comments:
<0> in terms of regular expression support, is grep and sed same? :) <1> i have two columns of texts, with lines like 100 dolphi-100, other line like 200 text-200.. i am looking for a way to transform this into 100 dolphi-x, 200 text-x .. i want to substitute the first word in second word, anyone knows how? <2> and the "x" is always the same? <1> yes <1> but not the 100, 200.. <2> yep <2> echo 100 dolphi-100 | sed 's/-.*$/-blahblah/'e <2> echo 100 dolphi-100 | sed 's/-.*$/-blahblah/' <1> but the 100 might be in any part of word.. <2> if i understood the point <2> so you only want to substitute the part after - which is the same with first column? <1> i may get a line like 100 www.test.com/100.jpg <2> and the result <2> like 100 www.test.com/x.jpg <2> ?
<1> no, the - generally will not be present. maybe i used a bad example <1> yes <1> i may do it in shell scripting.. <2> echo 100 dolphi-100.jpg | sed 's/^\([^[:blank:]]*\)\([[:blank:]]* [^[:blank:]]*\)\1\([^[:blank:]]*\)$/\1\2x\3/' <1> hmmmmm... <1> thanks o__o <2> nz <0> helloman: do you need -r for [:blank:] ? <2> no, i have GNU sed 4.1.4 <0> ok <2> I need -r for \| <1> how can i delet unmatched lines? currently i am doing a grep before the sed, to sed only matched lines.. <1> s/delet/delete/ <1> for unmatched lines, i meant.. unmatched in a substituition. lines that doesn't suffered a substituition.. hmm.. <2> /^How it looks like$/d <0> !d <2> :)) thats true <2> /^How it doesnt look like$/d <0> !d ? <0> ops :) <2> /^How it looks like$/!d <2> well <2> :) <1> like.. sed 's/regex/sub; /regex/!d' ? hmmmm.. <0> dark_light: like, forget the s <0> dark_light: like, only use what helloman showed. <1> but i want to substitute the regex if encountered <1> and delete lines that it isn't present <0> rite. do it in two steps then. <2> so delete the unmatched lines before <0> first get rid of bad lines, then do a s/this/that/g ;) <0> hmm, did -r support non-greedy flags? <1> you mean, sed '/reged/!d' | sed 's/regex/sub/' ? <2> no, sed '/regex/!d;s/regex/sub/' <1> but it's what i am doing with grep, and it's ugly.. why you are recommending this? <0> why is it ugly ;) <2> or <2> no, sed -n 's/regex/sub/p' <1> helloman, ah <1> o.o <2> this prints only substituted lines <1> hmm, nice <0> sed be fantastico. ;) <2> everyone loves it! <0> new star of the town ;) <2> :) <0> hulloh redduck666 <0> hmm, is the sed faq updated? <0> regarding gnu sed 3.02 3.02.80 "The N command no longer discards the contents of the pattern space upon reaching the end of file. This is not a bug, it's a feature. However, it breaks certain scripts which relied on the older behavior of N." <0> was this "fix" only for those two versions? <0> nevermind <0> http://pastebin.ca/99404 <-- althought it's rather oxymoronic script, why does it not work? ;) <2> what is it supposed to do? <0> put every line in hold space, when reaching the end of file print holdspace <0> but it appears to become and infinite loop <0> sedsed claims that it cannot find the label to jump to <2> it looks for me as if H adds always the first line <2> this works http://pastebin.ca/99419 <0> strange
<0> the n command is indeed a little bit confusing <3> Astinus-: read the next line of input (which will change the line number also -> = ) <0> m4n: well... <4> Hiho. I have a problem trying to use sed for search and replace on an IP address. Do I need to escape the . in the "replacement" string as well? <5> yes <4> gnubien: Is there an easy (commandline way) how I can get an IP address escaped or do I need to do some substring stuff? <5> swissmade: post an example of what you want sed to do <4> something like: car myfile | sed \s/196\.168\.0\.5/$dynamically_acquired_ip/g > new_myfile <4> oops s/car/cat <5> ok <4> gnubien: I get $dynamically_acquired_ip as a normal string, but it's a normally formatted IP address. Like 192.168.0.8 for example. <6> hum...how to output the line,the next 2 lines and the previous 2 lines which match the expression ? <6> thx! <5> swissmade: dynamically_acquired_ip="1.1.1.1"; echo "196.168.0.5" |sed 's/196\.168\.0\.5/'"$dynamically_acquired_ip"'/g' #1.1.1.1 <5> salamanders http://www.student.northpark.edu/pemente/sed/sed1line.txt AND sed.sf.net <5> salamanders: grep grep in sed1line <6> have greped...:( <5> salamanders: sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h # print 1 line of context before and after regexp, with line number indicating where the regexp occurred (similar to "grep -A1 -B1") <4> gnubien: Will try that. Thx! <6> gnubien:Will try that. Thx! :D <4> gnubien: Hmm.. I tried all sorts of using double quotes, single quotes and ` but nothing works. <5> swissmade: does my example work for you? <4> I think I got it. <4> Yes, the example works. <5> '"$dynamically_acquired_ip"' note the quotes <4> Yes.. I did note that. <5> ok, still have a problem? <4> The script has to be run as root, but I experimented not being root. And there's a permission error in the log output. <5> run the script as root? <4> Ah.. nope. Now it run fine, but it has put in $dynamically_acquired_ip literally. <5> making progress... <4> http://rafb.net/paste/results/C1eqvS31.html <4> Want the full script? <5> whats the problem now? <4> It replaces the old IP with $2 literally. <5> ok, no problems now? <4> No.. it doesn't put in 212.96.136.197 it put's in $2 (the string dollar-2 not the variable value). <4> I want to replace the IP address 212.96.128.171 in the file with the second argument from calling the script. <5> swissmade: ask in #bash ? <4> gnubien: OK :) <5> swissmade: greycat in #bash means but $2 in quotes = "$2" <4> So remove the ' around "$2"? <5> swissmade: maybe cat /sites/"$1"/zope/etc/zope.conf <5> try putting all the $1's in "$1" = quotes <4> Ha! removing the ' seems to work. <5> test it many times to see <4> I am. But it works now. (4 tests so far) <5> cool <4> Thanks! :) <5> have fun ;) <4> To be honest, bash scripting is not exactly my idea of fun. ;) <5> do what you like to do, more fun that way ;) <4> gnubien: That won't pay the bills <5> do what you love to do and find a way to get paid for it and you get paid twice ;) <4> gnubien: I tired that. Didn't work out. Possibly I'm not that good at what I love to do that people would pay enough. <4> (then again, I'm not that good at what I get paid for either. ;) <4> Sad existence, hu? <5> swissmade: follow your heart and do what you love cause the payback is better than money <4> gnubien: How old are you? :) <5> old enough to know better but young enough to be tempted to try it ;) <4> gnubien: I haven't lost all idealism (I'm trying to build my own company with my wife) .. <4> but my experience following that ideal has been rather sobering. <5> swissmade: yes, steep learning curve in life; simple life is the best imho <4> gnubien: Have you tried it? I have a vegetable path. Nice for stress relieve but I would not want to have my survival depend on it. ;) <4> s/path/patch <5> sure, tried it, liked it, live it <5> swissmade: our bodys need more than vegetables like fish oil, vitamin b, etc <4> I know.. not a vegetarian myself. ; <4> Gotta run! Nice meeting you and thanks again! <5> bye
Return to
#sed or Go to some related
logs:
#perl javascript SyntaxError: missing ) in parenthetical
#php #php tzap error while parsing inversion #linux #math #gimp startfluxbox terminate called after aborted fluxbox acer 5670 lirc
|
|