| |
| |
| |
|
Comments:
<0> redduck666: your script doesn't work if more than one whitespace characters are between the first and the second word <1> [ ][ ]* looks like it will work. <1> What it won't handle is the case where the first word has only one letter. ;) <2> 23:16:06 ~ $ echo 'word1 word2 word3' | sed 's/[ \t]*\([^ \t]\)[^ \t]*\([^ \t]\)[ \t][ \t]*\([^ \t]\).*/\1\2\3/' <2> w1w <2> goedel: now it works :) <3> oh, i was afk, sorry.. redduck666, thank you, it works <0> redduck666: sorry to disappoint you; it doesn't work if the first word consists only from one character <0> s/from/of/ <1> hehe. <0> my script is also not perfect: http://pastebin.com/870710 <0> perhaps better: awk '{print substr($1,1,1) substr($1,length($1)) substr($2,length($2))}' <0> but OT
<3> goedel, thanks alot <0> rew: you're welcome <0> good night; time too sleep <4> I have a bunch of CSS: I want to print the selector when the block contains certain text. The css is laid out like 'selector {\n\tproperty:\tvalue;\n\tnextproperty:\tnextvalue;\n...\n} <4> I'd like to print out 'selector {' if the junk between { and } contains 'float' <4> I guess I can do it in a couple pipes, but I wonder if there's a better way <5> I should learn how to do this in sed. <5> I can do it in awk. <5> awk '/[^{]*{/,/}/(/[^{]*{/){a=$0}(/float/){print a}' <4> what am I not understanding such that sed -n '/foo/,/bar/p' -e '/baz/p' file fails? <4> I mean, I know it doesn't do what I want, but why does it error out and say "can't read /foo/,/bar/p, no such file or directory" <4> ohh <4> need another -e <5> Ah right. <4> too bad you can't just do /{/,/float/,/}/p/ <4> er, you get what I mean <5> Yeah. <5> Well, it involves the Hold Space <5> and I've never gotten around to practising it <5> sed -n '/.*{/,/}/{/.*{/{h};/float/{g;p}}' <5> you can exclude the {} surround the h <5> Maybe one of those sickos, prec or BearPerson can show a better way :-) <6> hmm <5> hey man <6> so basically, you want "if between 'selector {' and '}' there is the substring 'float', print the string 'selector {'" ? <6> or do you want to print the entire selector{} block if and only if it contains 'float' somewhere? <5> selector { <6> sed '/selector {/,/}/ {/float/ i selector {; d}' <4> er <4> but I don't know what 'selector' is <4> or am I not understanding? <6> plus proper syntax <4> BearPerson: something like sed '/^\([^{]*\){/,/}/ {/float/ i \1 {; d}' ? <6> I don't think // groups can capture <6> kojiro, ah, so it's not the string 'selector', it's "the string in front of the {" ? <4> BearPerson: yeah, and I just discovered it's more complicated, some of these CSS have multi-line selectors <6> hrm <4> a,\nb,\nc {... <4> Someone suggested I use cscope <6> where does a selector start, then? <4> BearPerson: anything that's not between { } or /* */ is a selector <6> hrm <6> yes, a css parser would work wonders <4> well, cscope is a C parser, isn't it? <4> I haven't been able to find a decent CSS parser yet <5> make one! <5> There's probably a perl module to do it. <4> goldfish: no kidding, I should make one
<5> heh <4> With sed! (not) <5> The other one works, but not for multi-line selectors <4> I suppose the simplest (not the most efficient) way to do a parser would be to clear all newlines and create a literal hash <4> CSS really is just a hash of hashes <6> yeah, that's my favorite last-measure sed technique, though it is highly mem-inefficient <6> run stuff through tr '\n' '\a' and work on that <6> nowadays, I usually prefer smart usage of the 'N' command <6> sed -n '/{/,/}/ ! h ; /{/,/}/ {/float/ {s/.*//; x;p}} ; /}/ {s/.*//;h;}' <6> that might work somewhat rudimentarily <6> hrm, not quite, actually <6> sed -n '/{/,/}/ ! H ; /{/ H; /{/,/}/ {/float/ {s/.*//; x;p}} ; /}/ {s/.*//;h;}' <6> I'll probably get killed for that line if anyone who knows sed a bunch reads it, but it might work somewhat ;) <5> is there way to empty the current hold space? <5> ah. <5> {s/.*//;h;} is how you achieve it? <6> aye <6> put something empty into the hold space <5> cool <5> thanks <5> maybe they ran out of letters when they thought about adding that feature :) <6> gnu features are interesting <6> normally, extra nonstandard features are a standard method of vendor lock-in <6> I wonder if they're trying to achieve the same effect ;) <5> heh <7> hello <5> hi <7> i'm trying to filter binary files for certain patterns. the main problem i'm facing is that sed/grep seem to be line orientated, so i always get the whole line where my target expression resides. i just want to get the exact sequence of characters matching a certain regex, can sed do this for me? <1> Of course it's easy when this sequence does not span a newline. <1> sed and grep work with text files however, not "binary" files. <1> Consider converting your binary file to a text file, then using sed, then converting it back (if necessary). <7> i've tried 'grep -a' <1> grep is _still_ a tool to work with text files. <7> and converted with hexdump .. but it gets worse and worse. <1> grep will only print the lines which match. <1> If your input file does not consist of lines, then this isn't useful for you. <1> text files consist of lines of text, and so text-oriented tools are line-oriented. <7> is there a tool capable of returning just the matching string? <7> string meaning lower ascii range <1> grisu: Are you searching for strings in binary files? You may want to use 'strings' then grep its output. <7> okay.. that would be worth a try <1> strings some_executable_image |grep pattern <1> strings has special functionality when it works with object files and executables. <7> oh.. that looks much better now :-) <7> this should be easy from this point on <7> well, just that i didn't figure how to make grep/sed/awk returning just the match and nothing else (no characters before and after) <1> I know GNU grep has an option for this. <1> sed can do it too ... <1> http://rafb.net/p/gxaBoP87.html <7> i had "sed -n '/expression/p'" but it didn't really do what i want <7> -n '/expr/&/p' even <7> yes, it works - but is there away around this multiline solution? <7> maybe another tool which trims the output to just the matching region? <7> when grep is capable of colorizing the matching portion.. why shouldn't it be capable of printing just that? <8> grisu, "man grep" should tell you. <7> -o"hhh" :-) <7> thanks prec and Rado!
Return to
#sed or Go to some related
logs:
#debian at line 2: Duplicate entry 'localhost-mail' for key 1 ubuntu php5 mssql.so readlines remove \n Kernel panic - not syncing: Attemted to kill init setting sensor limits fail
#debian Error inserting scsi_transport_spi confog cah centos pam_mysql
|
|