Browsing articles tagged with "sed - Admins Goodies"
Nov 18, 2012
tom

perl + sed + remove lines that start with “#”

please advice I have linux and solaris machines, and I need command that work on both OS I use the following perl line in order to remove all lines that start with “#” why perl command not work , remark – need to support also lines that start with space or TAB and then “#” perl -i -pe ‘next if /^ *#/’ file . more file # aa a # bbb #xxx Asked by yael […]

Continue Reading »
Aug 19, 2012
tom

sed replace text – escape characters

I have a mysqldump file in which I want to replace the following text <a href=”/tag/ with <a href=”http://www.mydomain.com/tag/ but can’t find a way to correctly escape all special characters. I’m using the following command (+ a few other variants) cat wordpress_posts.sql | sed ‘s%/<a href=”\/\tag\/\/<a href=”\http:/\/\www.mydomain.com/\tag/\/%g’ > wordpress_posts_new.sql but it’s not working. Can anybody help? Update 1: Turns out that the source string in the mysqldump isn’t <a href=”/tag/ but <a href=\”/tag/ (note the […]

Continue Reading »
May 10, 2012
tom

sed + delete line only if line ended with specific character

need help – how to delete the line from the file if the last char is – “:” with sed , on Solaris machine for example sed will remove the following line (include the black line) /etc/val/config/globals.xml:/globals/CLUSTERNODES/node: example what not need to delete /etc/val/config/globals.xml:/globals/CLUSTERNODES/node:node1a Asked by yael sed -e ‘/:$/d’ < foo > foo.new will do the job (just tested it on Solaris 8, and it seems fine). Answered by MadHatter Check more discussion of […]

Continue Reading »
May 1, 2012
tom

sed not working in linux centos, ubuntu,

I have a simple script that gives me some values from a file. I am using sed to get that vaules (syntax is given below). these commands were working fine till yesterday. but now I’m not getting any value when i run these command. I’ve not changed anything so I’m quite surprized that what is reason. can anyone please tell me how can i debug my problem? below is file text: May 1 11:59:31 box2 […]

Continue Reading »
Apr 18, 2012
tom

use sed in shell script to replace IP Address in a file

I have a script that finds a string in a file replaces it with a new string. $ sed -i ‘s/$old_string’/’$new_string’/g’ $FILENAME Now I need the condition to be a regular expression that also check whether the old string is followed with anything but a number. I tried this but it didn’t work: $ sed -i -r ‘s/$old_string(^[0-9])+/$new_string/g’ $FILENAME Any idea? Asked by Elad Dotan To negate a range in a regular expression, the caret […]

Continue Reading »
Apr 10, 2012
tom

Find text, then insert linebreak and some php code across multiple files

I have a certain php code comment that appears in about 75 files across several users. This command succsessfully locates it. (I didn’t bother looking for the double slashes because I wasn’t sure about escaping them and they really don’t matter for this match.) grep -l -r “calls the myfunc() function” /home/*/public_html After I find it, I need to add a line break and some more php code like if($my_return_var===false){echo “<b>THERE WAS AN ERROR</b>”;} I […]

Continue Reading »
Mar 30, 2012
tom

bash/sed/awk/etc remove every other newline

a bash commands outputs this: Runtime Name: vmhba2:C0:T3:L14 Group State: active Runtime Name: vmhba3:C0:T0:L14 Group State: active unoptimized Runtime Name: vmhba2:C0:T1:L14 Group State: active unoptimized Runtime Name: vmhba3:C0:T3:L14 Group State: active Runtime Name: vmhba2:C0:T2:L14 Group State: active I’d like to pipe it to something to make it look like this: Runtime Name: vmhba2:C0:T1:L14 Group State: active Runtime Name: vmhba3:C0:T3:L14 Group State: active unoptimized Runtime Name: vmhba2:C0:T2:L14 Group State: active […] i.e. remove every other newline […]

Continue Reading »
Mar 15, 2012
tom

sed search replace enrypted string range [closed]

Possible Duplicate: My server's been hacked EMERGENCY my php based website got infected with malware, which added something like this in the code: <?php eval(base64_decode(“DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWh)); Now i want to replace all the “eval(” till its ending braces “));” with space or delete all those occurences, either with sed or other tools. i have tried this sed ‘s/eval\*/ /g’ code.php But its not working. What can be its solution? Thanks in advance. Asked by Frank As […]

Continue Reading »
Mar 14, 2012
tom

Why isn’t sed working?

I have a file that has a single line with a lot of ! characters. I want to remove all of the ! characters. I tried this: sed s/!// myfile and this: sed ‘s/!//’ myfile and this: sed ‘s/”\!*”//’ myfile But they all just print out all of the “!”. I must be missing something obvious. Any ideas? Asked by Greg_the_Ant Add a g to your regexp, for global replacement. Otherwise, only the first occurrence […]

Continue Reading »
Mar 8, 2012
tom

append to end of line sed / awk

This is probably easy and something is not clicking for me and my lack of coffee right now. I have a file with multiple lines that begin with a tab then the word GROUP something { Some of these lines for whatever reason drop the curly bracket under some conditions. The quick fix is to use sed/awk to append the curly bracket to that line but not lines where the bracket already exist. I’m halfway […]

Continue Reading »
Pages:12345678»