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
1answer
392 views

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) ...
1
vote
3answers
306 views

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

cutting relevant portions of a file [closed]

I want to cut some portions of binary file starting from a particular pattern and ending at a particular pattern.How do I do that in linux using bash.Can this be done using sed or awk? I have a file ...
1
vote
1answer
1k views

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

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

Recursively change the name of a file and the content inside the file if matches a keyword

I can use sed to do recursively find and replace a string in a bunch of files. Like so: find -name "*.py" -not \( -name .svn -prune \) -type f -print0 | xargs -0 sed -i 's/cat/dog/g' However is ...
17
votes
6answers
4k views

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

sed search replace enrypted string range [duplicate]

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 ...
2
votes
5answers
161 views

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 ...
1
vote
3answers
394 views

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

Prefix standard output before piping to a command

On Linux (Debian), how can I prefix the standard output of a command with one or several lines before piping it to a second command? This is for mailing the output of a command using sendmail like ...
2
votes
1answer
131 views

Recursively search and replace the contents of multiple file types

I have thousands of web files(*.php, *.htm, *.html, etc) that contain an absolute path(http://site.com/sites/etc). I need to scan a directory and all subdirectories for the various file types and ...
0
votes
1answer
752 views

llinux - replace subnet mask in ifcfg-eth0 with sed or awk

I have 30 linux servers that I need to change subnetmask. I want to use a simple script or a simple command to change the subnemt mask from 255.255.255.128 to 255.255.255.0 in ifcfg-eth0. can ...
1
vote
1answer
110 views

replace 'replacement character' for a database

Due to some encoding problems, some characters in my database have been interpreted uncorrectly. Some chars have been replaced with the 'replacement character'. I need to find all such chars and ...
3
votes
2answers
303 views

how to get text with sed?

i want to grab the the text between tok98 and 5678 and dump that out to a file. if the tok98 and the 5678 was on the same line i can use this sed -n 's/.*\(tok98\)\(.*\)\(5678\).*/\2/p' ...
0
votes
3answers
77 views

shell script + match MAJOR and CRITICAL strings from log file

I need to match lines that have MAJOR and CRITICAL strings that comes after the word ERROR:< any integer number > please advice how to do that with one awk or sed command? more HW_Log.txt ...
4
votes
4answers
2k views

Linux shell command to filter a text file by line length

I have a 30gb disk image of a borked partition (think dd if=/dev/sda1 of=diskimage) that I need to recover some text files from. Data carving tools like foremost only work on files with well defined ...
1
vote
3answers
213 views

Getting different values of particular variable from a file in UNIX

I have a file which I'd like to parse to extract certain values from it. I don't know what command and syntax I should use (maybe sed?). Below are 2 sample lines which I might expect to find in the ...
0
votes
2answers
312 views

How do I delete a matching line, the lines above and those below in the section?

In nagios config define service{ use generic-service host_name xxx.xxx.com service_description xxx Status check_command ...
0
votes
1answer
326 views

sed + not work on solaris

I run the following sed syntax on Solaris machine and on Linux machine on Linux machine sed do the JOB its remove all characters until the first number. but why this sed syntax not work on Solaris ? ...
3
votes
2answers
580 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 ...
4
votes
4answers
4k views

Parse and convert ini into bash array variables

I'm trying to convert an ini file into bash array variables. The sample ini is as below [foobar] session=foo path=/some/path [barfoo] session=bar path=/some/path so these become ...
0
votes
1answer
223 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 ...
0
votes
2answers
1k views

sed: Add new line to every file that does not have one at end of file

I am getting countless warning: no newline at end of file From some code that was last edited in Windows. In Linux, how can I fix all these cpp/h files and add a new line to the end of every ...
2
votes
4answers
259 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
79 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
86 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 ...
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
161 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
4k views

Regex for sed to grab multiple lines or a better way?

I'm creating a script that connects to a server and dumps the output to a tempfile. I want to use sed in the script to grab specific information from the temp file. The output would always have the 80 ...
4
votes
3answers
2k 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
961 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
939 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
324 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
229 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
135 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
645 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
1k 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" ...
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
158 views

Sed in Bash Difficult pattern

I have a complicated string that I need to search for and replace I need to replace: ...
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
300 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
158 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
334 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
151 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 ...
20
votes
8answers
36k 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
292 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 ...
1
vote
6answers
7k 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
715 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 ...