@# Quotes DB     useful, funny, interesting





Google
 
Web www.quotesdb.info
Undernet  |  EFnet  |  Quakenet  |  Freenode  |  Dalnet  |  Ircnet  |  Galaxynet
Page: 1 2 3 4



Comments:

<0> im new to sed.. how do you get it to actually do what you want instead of just outputting?
<1> lol
<1> What do you want to do?
<0> im having it replace a number in a script.
<0> so sed 's/121/127/'
<2> You have to redirect your output.
<0> OH
<0> well that's simple.
<1> yes.
<0> lol
<1> you'll need to use a temp file, though.
<0> thanks guys
<1> you'll need to use a temp file, though.
<0> why's that?
<1> Otherwise you'll hose your file.



<0> oh. alright.
<1> sed 's///' file > TMPFILE && mv TMPFILE file
<0> alright, thanks
<3> That worked well yesterday gold fish thanks.
<3> Would you be willing to explain the inner workings of the statement you gave me (If I paste it to you) I want to get a similar situation to work but I don't know the details of what you did.
<3> goldfish: Here's what you'd sent... sed -n "/define('DB_NAME', '/s/.*, '\([^']*\).*/\1/p" wp-config.php
<3> That processes lines like
<3> define('DB_NAME', 'dbe120982108'); // The name of the database
<3> I want to change it to process a line like this:
<3> $table_prefix = 'ss_'; // example: 'wp_' or 'b2' or 'mylogin_'
<0> okay, that didn't work. i mean, it worked, just not as i wanted it to.
<3> but that was not as simple as I thought
<3> (anyone else is welcome to reply too!
<0> i put it inside a bash script. read num; sed 's/121/$num/g' file > file2; but it actually puts $num in, rather than the input.
<1> blind: anything inside single quotes is taken literally
<1> i.e no interpolation of variables can occour
<0> oh. so do double quotes?
<1> that's one solution
<3> Darn I could have answered that one!
<0> good enough for me
<1> BrianLayman: :-)
<1> BrianLayman: Well, it's basically just a regular expression.
<3> One of the few thintes...
<3> Yeah but I'm getting mixed up at the /s/.*,
<3> Is that starting a substution at that point?
<1> yes.
<3> I didn't know you could do that in the middle....
<1> /define('DB_NAME', '/ just matches lines that have that pattern in them
<3> I got that.
<1> ok
<1> you can combine that with the s command.
<3> . replaces a single character,,,, OH ,* is any number of single characters..?
<3> Sorry .*
<1> .* matches anything (except a new-line character)
<3> Than the comma... Is that a literal comma?
<3> then not than (sorry pet peeve of mine)
<1> yes
<3> So, it must go backwards and remove the quote somehow?
<3> Is that the '\
<3> no... don't think so...
<3> here's the statement again
<3> sed -n "/define('DB_NAME', '/s/.*, '\([^']*\).*/\1/p" wp-config.php
<1> well
<1> that is irrelevant really, if you want to process your other line
<1> you'll just have to make a new regular expression
<3> Yeah, but I figured if I understood this one I could do that on my own. :)
<1> ok
<1> well, here's a hint.
<1> hm.
<1> or do you even need any?
<1> Just say it in english, it should be easy to convert.
<1> you want ss_ ? from your example?
<3> yeah,,, Is the $ at the start gonna cause problems?
<3> I don't think it should if I use single quotes
<3> So, my first attempt was this:
<1> it will yes.
<3> sed -n "/$table_prefix = '/s/.*; '\([^']*\).*/\1/p" wp-config.php
<1> you'll need to escape it
<1> \$
<3> OK



<3> So will
<3> sed -n "/\$table_prefix = '/s/.*; '\([^']*\).*/\1/p" wp-config.php
<3> work?
<1> no
<1> not if you want ss_
<3> see I need to understand what '\([^']*\).*/ is doing...
<1> ok
<1> it matches a ' then makes a backreference i.e \( , and it matches everything up until the NEXT '
<1> then ends the back reference \)
<1> then .* eats up the rest of the line
<3> processing...
<1> BrianLayman: .*; will eat up everything up to and including the last ; on a line
<3> OH! I seee
<1> so , you're result is behind that...
<1> A better approach would be to, match up to and including the FIRST ', then create a backreference, matching everything up to, not including the NEXT '
<3> OK, can you show me that and I'll learn from the differences. My brain is already fried at the end of a long day and my regex book is at work...
<1> ok.
<3> tnx
<1> .*'
<1> match up to and including the LAST '
<1> [^']*'
<1> match up to and including the FIRST '
<3> So, what would that make the whole statement?
<1> you tell me!
<3> OK... Hang on.. I'm finding the 1page cheat sheet site I had...
<1> no!
<1> use what i told you already
<1> 00:30 goldfish | it matches a ' then makes a backreference i.e \( , and it matches everything up until the NEXT '
<1> 00:30 goldfish | then ends the back reference \)
<1> That's basically, what you need to do
<1> And you know how to do them all.
<3> ok...
<1> "You can do it!"
<3> So we start with the same stuff modified a bit sed -n "/\$table_prefix = '/s
<3> That takes me up to the first quote
<3> I still want to grab everything after that up to the semicolon (Though I don't know why we don't go to the quote here)
<3> LOL I can't paste that part!
<3> here it is /.*;
<1> BrianLayman: no. /\$table_prefix = '/ doesn't take you anywhere
<1> that just matches lines that contain \$table_prefix = '
<1> it has nothing to do with the s command
<3> OH! That's right because we are not doing the grep any more... I forgot that....
<1> yes sir.
<3> OK... So that isn't like a starting reference point for the /s
<1> nope.
<3> well it is but only for the line.
<3> Ah it is a -n parameter yes?
<1> it just tells s command to execute on lines containing that pattern
<1> no
<1> -n just makes sed quiet
<3> darn.
<3> lol OK
<1> that means it wont print anything until p is used
<1> input == $table_prefix = 'ss_'; // example: 'wp_' or 'b2' or 'mylogin_'
<1> output == ??
<3> OH, that helps too.
<1> no
<1> i mean, what output do you want?
<3> OK so the s is on its own... let me look now
<1> yes
<1> but, what do you want to extract from the line?
<3> You want find the first quote, then find the second quote and backreference from there and put the result of that into the first result var
<1> :/
<1> Answer me!
<1> you want ss_ from the above example input?
<3> I want to extrat ss_
<3> YEs
<1> ok cool.
<3> Thought I said that earlier
<1> yes
<3> I thought you wanted a more wordy explaination. :)
<1> you want to find the first ', create a backreference up to and not including the next '
<3> the _ won't always be there and ti will be any length.
<1> yes.


Name:

Comments:

Please enter the result of the sum 63 + 46 (to avoid spam):






Return to #sed
or
Go to some related logs:

isapnptools dapper
ubuntu ftp source.list 403 Forbidden
ubuntu runlevels non-graphical
broken libofficebean.so requires libjawt.so
lamguage MPlayer
#math
#physics
#perl
#python
gentoo broadcom 4400 modprobe



Home  |  disclaimer  |  contact  |  submit quotes