| |
| |
| |
|
Comments:
<0> hi all. can someone help me, please? i need create script in sed or awk which find some config line and replace his. for example config file contains CONF1="192.168.0.1,root,,database" and i need replace this text. i am beginner. please help <0> i tried out=`cat config.cfg|grep CONF1` && sed -e 's/$out/new_configuration/g' > config.cfg but it's not works <1> if you have gnu sed, the -i option may help <1> sed -i 's/CONF1=.*/CONF1="some new config"/' config.cfg <2> but remeber to use backups <0> BearPerson, Thanks a lot <1> np <3> how do I delete all string that have more than 3 characters? <4> /^....*$/d <3> doesn't work <3> no <3> working =)
<4> :) <5> llm0: sed 's/[^ ]\{4,\}\s//g' or similar (not optimal, but i'm no expert either) <5> does not delete work at the end of a line. hm <5> sed 's/\<[^ ]\{4,\}\> *//g' file maybe somebit better <6> hi everyone <4> hi <7> is something like: "sed -i.BAK 's|foo|bar|g' *" valid for all files in a directory? <8> depends on your shell's interpretion of "*", but usually yes ;) <7> and to do two find/replaces at once, can I do this: "sed -i 's|foo|bar|g' -i 's|foo2|bar2|g' *" ? <8> -i 1. works only on GNU sed, as sed is and always was a STREAM editor, and 2. i doubt you can use it per-expression <7> ah.. nevermind. it's "sed -i -e 's|foo|bar|g' -e 's|foo2|bar2|g' files" <8> if you want to edit text files, why don't you use a file editor, rathen than a stream editor? <7> because i want to make two changes to 100 files at once. :) <8> -e 's|foo|bar|g;s|foo2|bar2|g' ? <8> with "use a file editor" i didn't mean "use a file editor you can't script" <8> i only said "use a file editor" <8> ed(1) <8> ex(1) <8> even vim(1) is scriptable <8> sed on multiple files raises problems, sometimes. if it works for you, okay. <9> hi <9> I'm attempting to parse a large data file (in this format http://paste.lisp.org/display/25822). Any ideas how I could transform this into CSV format? Any help would be appreciated. <10> rellis: freshmeat.net search: convert cvs ? <9> That's way too obvious, I don't like it =p <10> rellis: hehe, ok, lets obfuscate it then ;) <9> hehe <9> Hmmm, I ran that search a couple different ways but I don't seem to see any projects involving reformatting data like that. <10> rellis: ok, i dont know what cvs format looks like, html? <9> oh, csv is comma seperated variables <9> like... company name, address, phone number, work number, more info <9> instead of how it is in the link i posted <10> rellis: ok, if you post a simple example line of text for before and after sed edit, we might try it <9> alright, let me conjur one up real quick <10> ok <9> gnubien: http://paste.lisp.org/display/25823 <10> ok <9> Did that better explain what I'm trying to do? <9> Trying to get it in some format in which I can import into a DB, csv just seems the simplest. <10> rellis: why the double ,, after one phone number? <9> because the field phone_main2 is blank <10> ok, i see <9> on the second line i accidently put ,, before unknown <9> that should be 1 comma <10> ok <10> rellis: easiest first step is to ask in #bash to see if anyone has done it before which i have not; looks like its do-able but complex <9> Alright, thanks. <9> I'll hit them up. <10> rellis: ask: anyone converted a text file to cvs format? or the like someone may have a faq on it already <9> Okay, cool. Ya, it seemed like something someone may have already needed to do to me as well... <10> rellis: yea, be courteous and you will get some info hopefully
<10> rellis: wait patiently for 5 minutes or so to see if anyone has a brain-storm ;) <10> rellis: if your doing this for homework i want beer and pizza emailed to me first ;) <10> rellis: delete all newlines: sed -e :1 -e '/"$/!{N;s/\n/ /;b1' -e '}' filename this will make the file all one line <10> rellis: the insert /n at the "Company Name" to break it into lines with every company name's info all on one line <10> rellis: then sed the lines to the format you need, tada ;) <9> I'm being very courteous, it seems like everyone in that channel is twelve years old =/ <9> heh <10> rellis: thats if you need to use sed exclusively <10> rellis: yea, i threw you to the lions ;) thats why i said be courteous <9> hehe <9> always... <10> rellis: they are offering some good ideas and a few abuses to spice up the mix ;) <9> gnubien: Hehe, ya. <9> gnubien: It's IRC, I think a thick skin is a requirement. <10> rellis: yes it is <9> gnubien: Oh, and this is definitely not homework. <9> heh <10> oops, no beer and pizza for me then <9> hehe <10> rellis: sed -e :1 -e '/"$/!{N;s/\n/ /;b1' -e '}' filename |sed 's/COMPANY NAME/\nCOMPANY NAME/g' #all company name data should then be on one line <10> rellis: sed -e :1 -e '/"$/!{N;s/\n/ /;b1' -e '}' cvs.conv |sed 's/COMPANY NAME/\nCOMPANY NAME/g' |sed 's/COMPANY NAME\|Main:\|Fax:\|Member Count://' #removes the line titles <10> cvs.conv is my test file <10> rellis: you a total newbie at sed? <10> rellis http://www.student.northpark.edu/pemente/sed/sed1line.txt AND sed.sf.net <11> how do i match cpu and not cpus? using something like s/^cpu$/name/g doesn't seem to work <10> hell``: echo "match cpu and not cpus" |sed '/cpu[^s]/s/cpu/CPU/' #match CPU and not cpus <9> gnubien: Sorry, I had a quick staff meeting =/ <11> gnubien: is the first '/cpu[^s]/' there telling it what not to match? <9> gnubien: I'm going to play around with a bit more and get the addresses to always be on two lines, then work with it from there. <9> gnubien: Having the data formatted as it is makes it much more difficult than it should be, I think. <10> hell``: yes, anything with the [^something] means not this <10> hell``: the caret in the box means: not this <11> gnubien: i understand that but i mean't how you have it setup at the beginning of the sed line <10> rellis: if you can use awk you can selective print the words you want and use the , seprartor too <11> gnubien instead of something like s/blah/this/g you have /cpus[^s]/s/this/blah/g <10> hell``: post an example line of text before and after the sed edit <9> gnubien: Thanks for the help :) <10> rellis: sure, have fun ;) <11> gnubien: what you have is correct and working for me, i'm just trying to understand how you have it written, im used to seeing something like 'sed s/this/now/g' and you have this other part '/cpus[^s]/s/this/now' at the beginning <11> so im guessing cpus[^s] at the beginning is telling it what not to match <10> hell``: ok, sed '/cpus[^s]/s/this/now' means: search for regex cpus but not "cpuss" and if you find it substitute the word "this" for "that" on the line that you found "cpus" <10> hell``: so you probably want sed '/cpu[^s]/s/this/now' which searches for "cpu" but not "cpus" <11> ok i understand now <11> thank you <10> hell``: sure, email me some beer and pizza if thats homework ;) <11> lol <11> no i completed my homework a couple years ago :) <10> hell``: http://www.student.northpark.edu/pemente/sed/sed1line.txt AND sed.sf.net <11> gnubien: so you could do: s/cpu[^s]/this/g and it should do the same thing? <10> hell``: s/cpu[^s]/this/that/g works, you post creates: echo "match cpu and not cpus" |sed 's/cpu[^s]/this/g' #match thisand not cpus <11> ah <10> hell``: http://www.grymoire.com/Unix/Sed.html <9> Is there a way using sed to match a pattern and if the line matches that pattern merge it with the line directly above it? <12> rellis: there is <12> using the hold space for the previous line or something <12> afaik, it's in eric pement's one liners <12> or, grymoire's url <12> http://www.grymoire.com/Unix/Sed.html#uh-0 <12> and google eric pement sed , look for his one-liners page <13> how can i append text to the end of each line ? a\ doesn't work because it creates a new line .
Return to
#sed or Go to some related
logs:
#perl install vmware debian etch #web fc5 configure lirc #php #linux #ldap #css find symbolic links linux xorg.conf tridentfb
|
|