Browsing articles tagged with "sed - 6/8 - Admins Goodies"
Aug 15, 2011
tom

Sed Replace Help

I need some assistance with some sed replaces: sed -ri ‘s#logging { /* If you want to enable debugging, eg. using the ‘rndc trace’ command, * named will try to write the ‘named.run’ file in the $directory (/var/named”). * By default, SELinux policy does not allow named to modify the /var/named” directory, * so put the default debug log file in data/ : */ channel default_debug { file “data/named.run”; severity dynamic; }; }; #logging { […]

Continue Reading »
Aug 15, 2011
tom

How to extract hostname from $(who am i)

I try to extract the hostname from the following string (created using who am i): username pts/0 2010-10-05 17:30 (www.example.com) I need a solution which also works if (www.example.com) is not present which is the case when I am logged in locally. Furthermore the solution also has to work on a Mac where who am i returns the following string: username ttys006 Oct 5 16:47 (www.example.com) The problem is that the mac puts spaces in […]

Continue Reading »
Aug 14, 2011
tom

Using #!/bin/bash script

I am trying to develop a script that will automate setting up a new virtual hosting domain on my server, I have a custom setup on my server that gives every domain a username and password but no shell access. (this is do to vsftpd using system users) It also creates a directory in the /var/www/sites/”domainname.com” with all of the default files in it. Then created a /etc/apache2/sites-available/domaindname.com Apache Conf file for the Virtual Host. […]

Continue Reading »
Aug 13, 2011
tom

Preventing mysqladmin proc from messing up my terminal

We do a lot of queries with binary data in them, and because of that, sometimes when I run “mysqladmin proc”, my terminal gets messed up. Running reset fixes it, but I’d prefer to just prevent the problem in the first place. How can I strip these out with sed? Or is there a better way to do it? You can pipe to cat -v (should show “non-printing” characters in escaped notation) Check more discussion […]

Continue Reading »
Aug 13, 2011
tom

sed works properly in SSH, not in PHP

So, I have the following line that I run in PHP with exec($addPHPtags); $addPHPtags = “/bin/sed -i ‘/<BODY BGCOLOR=”#FFFFFF”>/ a <?php n ?> ‘” . $instance[‘file’] . ” 2>&1″; I’d expect that command to find the key and append it with a php tag. However, when I run it in PHP, I get the following error if I trap command output: [0] => /bin/sed: -e expression #1, char 39: unknown command: `?’ However, if I […]

Continue Reading »
Aug 13, 2011
tom

sed with several matches

The two “sed lines” only differ by a “n” below.. How can i get this output [no new line before the </pre>]? [ http://pastebin.com/raw.php?i=ED34jvtF ]: . . something3 </pre> something4 . . $ echo -e ‘something1nsomething2nsomething3nn</pre>nsomething4nsomething5′; echo “######################################”; echo -e ‘something1nsomething2nsomething3nn</pre>nsomething4nsomething5′ | sed -e N -e N -e “s#n</pre>#</pre>#g” -e P -e D something1 something2 something3 </pre> something4 something5 ###################################### something1 something2 something3</pre> something4 something5 $ $ echo -e ‘something1nsomething2nsomething3nn</pre>nsomething4nsomething5′ | sed -e N -e […]

Continue Reading »
Aug 12, 2011
tom

Recursively rename files using find and sed

I want to go through a bunch of directories and rename all files that end in _test.rb to end in _spec.rb instead. It’s something I’ve never quite figured out how to do with bash so this time I thought I’d put some effort in to get it nailed. I’ve so far come up short though, my best effort is: find spec -name “*_test.rb” -exec echo mv {} `echo {} | sed s/test/spec/` ; NB: there’s […]

Continue Reading »
Aug 12, 2011
tom

sed +append number after last matched word in line

I have log file called: log.txt my target is to add the parameter: $PARAM only after the last string: “Number” in the file log.txt remark: PARAM could be any number example: PARAM=34.43435454 tail -10 log.txt date 12.3.2010 Number 2.34 date 12.3.2010 Number 2.14 date 12.3.2010 Number 34.43435454 someone have idea how to do that with sed? After “Number” on every line: sed “s/.*Number/& $PARAM/” log.txt After “Number” on the last line: sed “$s/.*Number/& $PARAM/” log.txt […]

Continue Reading »
Aug 12, 2011
tom

How to rename multiple files by replacing word in file name?

Replace ACDC to AC-DC For example we have these files ACDC – Rock N’ Roll Ain’t Noise Pollution.xxx ACDC – Rocker.xxx ACDC – Shoot To Thrill.xxx I want them to become: AC-DC – Rock N’ Roll Ain’t Noise Pollution.xxx AC-DC – Rocker.xxx AC-DC – Shoot To Thrill.xxx I know that sed or awk is used for this operation. I can’t google anything so I’m asking for your help =) Could you please provide full working […]

Continue Reading »
Aug 12, 2011
tom

Help with SED command to replace text in several files

EDIT: I found the solution. This command works, in case someone finds it useful. The i.bak modifier makes a backup of every changed file. find /pathoffilestochange -name “*.php” | xargs sed ‘s|/wrong/path/|/correct/path/|g’ Hello, I want to change a path inside dozens of .php files. I dont know how to use sed, but I got this command somewhere on the internet before and have succesfully used it. find /ruta -name “*.txt” | xargs sed -i.bak ‘s/charset=Foo/Bar/g’ […]

Continue Reading »