Sed stands for Stream EDitor - one of the basic tools in the POSIX environment. It processes one or more files according to an editing script and writes the results to standard output. Created in Bell Labs, it has been around since mid-70s.

learn more… | top users | synonyms

2
votes
1answer
1k views

problem executing a bash script with utf8 encoding

I have a bash script encoded in utf8 . Within the script i use sed command using ยง as a separator . Now when i run execute this script sed complains about the separator. If i use normal char as a ...
2
votes
2answers
984 views

How to use sed, perl to rename files and its contents with a particular pattern in a given directory?

Given a directory "Centos1" which has few files named Centos1.x, Centos1.y, Centos1.z and these files also has "Centos1" in their contents. Using a single command ( using find, sed, perl -pie ) how ...
0
votes
4answers
416 views

sed replace slash

am using !/bin/bash for fl in *.txt; do mv $fl $fl.old sed 's/files.php?file=/file/g' $fl.old > $fl rm -f $fl.old done I need the output replaced with file/ not only ...
1
vote
1answer
245 views

Using Find, Grep, Awk, or Sed To Rename Server After Cloning

My client tells me they have cloned a VM in VMWare of an Ubuntu Linux server. Now it's my job to get into all the files and find out what still has the old server name of "bishop" and change it to ...
1
vote
2answers
142 views

Using SED to update .htaccess with blocked IP addresses

I have a file that has a list of "bad" IP addresses. I want to import this file of bad IP addresses into my .htaccess file to deny access via apache. I want to automate this process using sed. How ...
1
vote
4answers
787 views

Bash: delete all but most recent n files with prefix x

I have a directory of backups that looks like this: -rw-r--r-- 1 ftpuser ftponly 5610595 May 27 00:01 alpha-114.tar.asc -rw-r--r-- 1 ftpuser ftponly 50559368 May 27 00:04 beta-211.tar.asc ...
4
votes
3answers
2k views

SED replace across multiple lines

I am trying to find these three lines: <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> --> and replace them with: <Connector port="8009" protocol="AJP/1.3" ...
2
votes
2answers
159 views

Sed in Bash Difficult pattern

I have a complicated string that I need to search for and replace I need to replace: ...
0
votes
2answers
207 views

How to get HTTPS cert?

INPUT: echo QUIT | openssl s_client -connect mail.google.com:443 | sed -ne '/BEGIN CERT/,/END CERT/p' OUTPUT: depth=2 C = US, O = "VeriSign, Inc.", OU = Class 3 Public Primary Certification ...
2
votes
2answers
2k views

Permission Denied when using Sed

I am using Sed to find and replace a string in a file. This is the first time working with it so I maybe doing it wrong, I have a file thats owned by "root" called "test.properties" and I want to ...
-3
votes
2answers
320 views

Is running this SED command safe? [duplicate]

Possible Duplicate: My server's been hacked EMERGENCY Hello, my whole site got hacked possibly by a wordpress exploit, i am in a hurry to explain in detail, but PLEASE do me a favor and ...
3
votes
3answers
1k views

sed insert from file.txt to multi files

I've this sed & find command find /home/www/ -name footer.php -exec sed -i 's/<\/body>/testmoe\n<\/body>/' what I need to replace testmoe with data in file.txt so its gona be , ...
0
votes
5answers
161 views

Sed regexp /d deleting whole file

Given a typical known_hosts file: [123.45.67.89]:22 ssh-rsa bbuivvhbkbjdnflksndkfnksnfk... [98.76.54.32]:14444 ssh-rsa hohdibsodbfoasbfbsabdfbsd... [77.34.122.33]:32209 ssh-rsa ...
2
votes
6answers
768 views

Using sed to convert hex characters in postgresql dump file

I am working on moving several databases from a Postgresql 8.3 server to a Postgresql 8.4 server. It has worked fine so far, but one base has given me some trouble. The database is listed as ...
1
vote
3answers
155 views

alias to replace a text in file

here is a practical situation.I facing some of my files where there is a common string in these files.I usually will open vi and do some thing like :%s/text/replacement/g and I have to do it in ...
0
votes
2answers
357 views

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 ...
2
votes
6answers
10k views

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 - ...
2
votes
1answer
923 views

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 ...
1
vote
2answers
2k views

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 ...
1
vote
1answer
84 views

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 . ...
0
votes
2answers
66 views

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 ...
1
vote
1answer
867 views

replace text in file without overwriting file

I want to use the command line to edit a text file but not overwrite it. I want to preserve the owner, group, and permissions of the file. I have a file that holds a count of the number of times a ...
0
votes
1answer
671 views

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 ...
1
vote
1answer
367 views

sed can't find a file that obviously exists

I run the following command which comments out all lines that contain the text "dlclose" grep -lIR "dlclose" . | grep -v ".svn" | xargs sed -i "s/.*dlclose.*/\/\/&/g" However, sed claims that ...
3
votes
4answers
780 views

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 ...
0
votes
1answer
98 views

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 ...
1
vote
1answer
123 views

Mail-merge like operation with sed (or similar)

I would like to perform the following operation: Given a file like this: update FOO set STATUS="X" where ID=<REPLACE>; insert into BAR (Z,W) values(<REPLACE>, 42); And a file like ...
1
vote
1answer
376 views

shell script to iterate through text files and delete a string

I have a few hundred text files in one directory with lists of users: &usera &userb userc &userd note that some do not lead with the &. Also, in some files, the last line does not ...
1
vote
1answer
1k views

use SED recursively in linux?

I want to implement the following command recursively sed -i 's/href=\"1\//href=\"\/1\//g' ./* so that it replaces all href="1 with href="/1 in all sub-directories. Is there a flag I can add to ...
1
vote
1answer
315 views

Comment all lines matching some pattern

I need to comment out all lines containing "dlclose" for each file in the current directory and any sub-directories (recursively). This is my best guess so far given what I was able to find out from ...
1
vote
3answers
95 views

Taking this, and making that

I had no idea how to word the title. I need to take an output such as: [~]# cat file user1 domain1.com user2 domain2.com user3 domain3.com and turn it into an output such as: user1 domain1.com ...
3
votes
2answers
222 views

unix script problem

I have a simple script which runs on a FreeBSD machine with the following code: #!/bin/sh `sed -i .bak '\:#start 172.0.0.3:,\:#end 172.0.0.3:d' /usr/local/etc/racoon/racoon.conf` echo $? It should ...
0
votes
1answer
739 views

Cannot cd to parent directory with cd dirname

I have made a bash command which generates a one liner for restarting all Weblogic ( 8,9,10) instances on a server. The script works well but I need a suggestion to make it better using the dirname ...
4
votes
2answers
232 views

Perl search & replace

How can I use search and replace to change the contents of a file. I need to be able to change the 'all to none' and/or 'none to all' without having to manually do it every time for hundreds of ...
1
vote
2answers
327 views

sed to update xml file

I want to update <MySettingsSettings enabled="false" logFilePath="E:\server.log" /> to <MySettingsSettings enabled="true" logFilePath="D:\server.log" /> How can I do this through ...
0
votes
2answers
189 views

How can I echo changes made in a sed expression to the console?

I have a simple sed expression: sed -i 's/foo/bar/g' blat.xml Because the expression modifies the file in place it is hard to see which lines were changed. Is there a way to echo the modified ...
1
vote
2answers
171 views

Wondering why sed isn't working with xargs like I expected

I am wondering why the following command wouldn't work: sudo find . -name index.htm | xargs -0 sudo sed -i 's/pattern1/pattern2/g' When ran the two commands separately, they worked as expected, ...
0
votes
2answers
443 views

Running (vertical?) diff on columns in a file

in our company we pull in inventory files from third parties. These files are in a fixed format, containing the 13-digit EAN (think UPC code) as well as other data. I also have a master list of EANs ...
0
votes
2answers
2k views

Extract 1 IP address from 2 or more in a line of text

I have about 30,000 Apache access logs, some of which list multiple client IP addresses. This is as a result of Apache logging the X-Forwarded-For header instead of the IP address of the client. The ...
1
vote
2answers
891 views

sed php.ini memory_limit

The following works great: phpmemory_limit=256M #or what ever you want it set to sed -i 's/memory_limit = 16M/memory_limit = '${phpmemory_limit}'/' /etc/php5/apache2/php.ini If the memory_limit is ...
1
vote
5answers
1k views

bash script - print from line N to EOF

I want to be able to print the number of lines from bash as such: Line number (as counted from the top) -> end of the file It seems tail will only count lines from the bottom. Does anyone know how ...
0
votes
7answers
774 views

vi syntax to comment out non-commented lines (cron)

Anyone know if it's possible in vi to replace only uncommented/non-blank lines with comments? If I want to replace a commented line with something I know I can use :%s/^#/##foo##/g -- but I am ...
2
votes
3answers
4k views

How to get all running process ids only?

I know that ps ax returns the pids 1 ? Ss 0:01 /sbin/init 2 ? S< 0:00 [kthreadd] 3 ? S< 0:00 [migration/0] All I need is to clean those strings, but I ...
1
vote
3answers
3k views

SED Find & Replace w\ Regular Expressions

Alright, So i'm confused & out of ideas. I'm trying to replace all the old IP addresses with a new one. find -type f | grep \.php$ | xargs sed -r -i ...
2
votes
3answers
996 views

Getting correct linefeeds in emails generated from linux

I have a script that emails certain linux log entries to me, and I read the email in MS Outlook. The problem is that all the lines run together with no linefeeds between the lines. To address this I ...