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

3
votes
2answers
712 views

How do I use sed or awk to remove text?

I have the following line in a file: Linux Release............5.4.2.0-02 12_12_2011_07:31:23 How do I remove all characters before the first number with sed or awk? I wish to get the ...
0
votes
1answer
289 views

Sanitizing dates using sed or awk on an ldapsearch query

I'd like to pipe the output of an ldapsearch to sanitize the dates returned - I presume sed and/or awk can help with this but would appreciate a bit of help. The fixed length date format in the LDIF ...
2
votes
4answers
356 views

Is there a sed equivalent to awk -F ':' '{print $2}'?

Maybe someone can help me to find (the most simply) the equivalent of this following awk command with sed: echo "first:second:third"|awk -F ':' '{print $2}' second
0
votes
1answer
85 views

Parse value of $DatabasePassword from RT_SiteConfig.pm

I'm writing a Bash shell script to backup our Request Tracker (RT) MySQL database on a daily basis. Instead of hard-coding the MySQL database user's password in the shell script I'd like to parse it ...
0
votes
2answers
98 views

Display specific word in file. To be used as varible, grep for email in log

I'm looking to display just the email address in the /var/log/secure file. The email goes into a variable, so just grepping for lines won't work. I know how to string together sed commands, but is ...
3
votes
2answers
2k views

How can I use grep to find the most frequently recurring errors in my log file?

I've got a PHP application that is generating large amounts of warnings and notices in the log file.. I'm fixing these one at a time. I would like to be able to fix the most frequently occurring ...
2
votes
2answers
1k views

AIX sed parsing error 0602-404 but works with Linux sed?

I have this sed working in Linux and have a few AIX servers I need to use it on as well but keep getting this error and I can't find any information on it even though it's specific. Got the following ...
4
votes
1answer
173 views

sed search line and replace only text in that line

i want to use sed to replace any x(small) to 0 if the line contains Z(capital) x,Z,y y,X,z, Y,z,x x,Z,y
4
votes
3answers
3k views

grep or sed to find a integer value above a given amount?

This is in reference to another question: How do I use robocopy to list all files over a certain size recursively? I would like to parse output of a command (or cat a log file) and find a string ...
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
1k 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
482 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
258 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
148 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
923 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
168 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
209 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
353 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
163 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
803 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
158 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
441 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
1answer
1k 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
87 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
68 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
985 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
686 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
516 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
835 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
105 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
140 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
378 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
344 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
761 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
233 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
337 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
196 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
450 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
1k 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
854 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 ...