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
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
335 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
162 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 ...
-1
votes
3answers
400 views

unix command to remove empty lines in a file

How do I remove empty/blank (including spaces only) lines in a file in Unix/Linux using the command line ? contents of file.txt Line:Text 1:<blank> 2:AAA 3:<blank> 4:BBB 5:<blank> ...
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 ...
23
votes
8answers
43k views

how to find out mac addresses of all machines on network

Is there some easy way to find out mac address of all machines on my network rather than doing an SSH into each and ifconfig | grep HWaddr if there are 300 machines on network I really need some easy ...
0
votes
2answers
404 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 ...
3
votes
6answers
12k 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
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
86 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
287 views

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"; ...
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 ...
0
votes
1answer
682 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 ...
3
votes
4answers
812 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
102 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 ...
0
votes
2answers
2k views

sed/awk: extract one number from string

I have many lines like the following being returned from a bash command, with different sourceNodeIds of varying digit lengths: <NodeAssociation sourceNodeId="33654" [...] sourceNodeEntity="Issue" ...
2
votes
6answers
794 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
1answer
131 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
440 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 ...
1
vote
1answer
334 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 ...
4
votes
2answers
640 views

How do I prevent bash $ substitution?

I'm trying to preserve $if below and would like the following to output $if bash is getting in the way by doing $ substitution $ sed -e 's:\\$:\\$:g' <<ENDOFFILE > $if > ...
1
vote
1answer
931 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 ...
2
votes
2answers
977 views

How can I remove malware code in multiple files with sed?

I've this malware code in so many .html and .php files on the server. I need to remove them using sed -i expression search all files under directory /home/ find infected files remove the code by ...
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 ...
4
votes
6answers
2k views

How to remove a tagged block of text in a file?

How can I remove all instances of tagged blocks of text in a file with sed, grep, or another program? If I have a file which contains: random text // START TEXT internal text // ...
4
votes
5answers
1k views

Is it worth while to learn Awk?

I am decent with bash scripting and I am catching on to regex, and a little sed usage. Is learning awk still worth while with all the alternatives out there. Opinions?
20
votes
5answers
47k views

How to display certain lines from a text file in Linux?

I guess everyone knows the useful Linux cmd line utilities head and tail. Head allows you to print the first X lines of a file, tail does the same but prints the end of the file. What is a good ...
0
votes
1answer
748 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
332 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 ...
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
447 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 ...
2
votes
3answers
394 views

How to grab a word from a file using sed or grep

I am trying to pull a piece of text from a file to use as input for the next command. The word always starts with "JID_" and then some random numbers/characters after that. For example : ...
9
votes
3answers
1k views

read specified range of lines from a file

I have i file that contains 100000 line how i can get the lines from line# 5555 to line# 7777 under linux. Thanks for all.
1
vote
2answers
973 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 ...
0
votes
2answers
192 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
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
814 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 ...
0
votes
5answers
2k views

How to recursively search and replace from command line on unix/linux system

So I want to change several files at one with one command. This is what I have so far: find -regex ".*\.ext$" | xargs grep -l searchText 2> /dev/null | xargs -i sed 's/searchText/replaceText/' ...
2
votes
3answers
5k 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 ...
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 ...
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
1k 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 ...