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
4k views

Using sed to remove both an opening and closing square bracket around a string

I'm running this command in a bash shell on Ubuntu 12.04.1 LTS. I'm attempting to remove both the [ and ] characters in one fell swoop, i.e. without having to pipe to sed a second time. I know square ...
-2
votes
1answer
123 views

linux + count how many digits in IP address [closed]

I write the following syntax (exist in my ksh script) in order to find how many digits I have in IP address IP_address=127.1.1.1 echo $IP_address | sed s'/\./ /g' | wc | awk '{print $2}' 4 . ...
0
votes
3answers
1k views

Remove a sentence which starts with word “mark” and ends with “;”

I am having 100's of files that contain sentence that starts with mark and ends with semicolon(;). eg: mark is driving a car; i need to remove every sentence starts with mark and end with ";" How ...
2
votes
3answers
173 views

linux + match only VALID IP from text file into other file

please advice how to match only the valid IPs ( 255.255.255.255 ) from the file.txt and insert only the valid IP into VALID_IP.txt file ( see VALID_IP.txt for example ) the solution should be ...
0
votes
1answer
262 views

perl + sed + remove lines that start with “#”

please advice I have linux and solaris machines, and I need command that work on both OS I use the following perl line in order to remove all lines that start with "#" why perl command not work , ...
2
votes
2answers
999 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 ...
-3
votes
2answers
315 views

linux + solaris + delete all characters in file except numbers and dot char [closed]

please advice how to delete all characters in file except numbers and "." Should be implemented by sed or awk or perl ( one line ) or any other idea , so I will add the syntax in my ksh script ...
0
votes
1answer
76 views

Remove all words that DOESN'T contain a colon [closed]

I have a file with this type of lines: blabla bla:bla whatever what:ever alpha bravo charlie del:ta I only want to keep the words that contain a colon. So the output for the above would be: ...
1
vote
1answer
396 views

Writing to /etc/networking/interfaces at boot using sed/awk?

Newbie here, I'm trying to write to an auto-generated /etc/network/interfaces file of a newely provisioned XEN Ubuntu (12.04/10.04/8.04) DomU server at boot time using (currently) sed. The ...
3
votes
2answers
234 views

Extracting a line section of mysql backup using sed

I occasionally need to extract a single record from a mysqlbackup To do this, I first extract the single table I want from the backup... sed -n -e '/CREATE TABLE.*usertext/,/CREATE TABLE/p' ...
3
votes
5answers
2k 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?
0
votes
1answer
98 views

script for changing file dates of postfix Mailbox files

I have a Maildir structure, that got wrongly restored from backup and all files have the file date of the restore instead of when they have been created/received. What would be the best way to ...
4
votes
4answers
6k 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
2answers
127 views

linux + create host file from CSV file by sed or awk or perl

I have the following CSV file this file defined which Linux machine exist in the system and there ip's my target is to create host file from this file please advice how to create host file as ...
2
votes
2answers
1k views

How can I add a line break before a set of values going into a bash script?

I've got a set of data piping into a bash script. Here's an example of what that data looks like: "foo1": "Miscellaneous text", "foo2": "More text", "foo3": "blah blah blah", "foo4": ...
-2
votes
3answers
3k views

sed replace text - escape characters

I have a mysqldump file in which I want to replace the following text <a href="/tag/ with <a href="http://www.mydomain.com/tag/ but can't find a way to correctly escape all special characters. ...
0
votes
1answer
153 views

Replace Javascript malware code with empty string [duplicate]

Possible Duplicate: My server's been hacked EMERGENCY I have following code in hundreds of my html and js files: ...
7
votes
2answers
1k views

bash sub-string extraction for specified start and end character

For example I have a log file having this entry: [Wed Aug 08 11:39:41 2012] [error] [client 155.94.70.224] ModSecurity: [file ...
2
votes
1answer
219 views

encapsulate text in quotes with sed buffer

I need to do a search and replace to encapsulate a variable string in single-quotes (php object notation into php array notation) such that the following block: $my_trip->trip_id = ( ...
1
vote
1answer
136 views

sed replace inside shell file

I have a shell file which needs to perform a replace of some text in a php file. The line that needs replacing is: $database = $db."_db"; The actual sed command needs to contain a variable so not ...
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" ...
0
votes
2answers
2k 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 ...
0
votes
3answers
254 views

How to join a variable number of lines

I have a file with Feature names and a variable number of usernames below: Feature1 user1 user2 Feature2 user3 I'd like to be able to move the usernames to the same line as the Feature name ...
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
2answers
155 views

Gathering IP's from a complicated log

I have a question regarding the use of some more advanced grep, awk, sed. I have a log file, for a proprietary MTA, that contains IP's in a string, delimited by [redacted]^~x.x.x.x^[redacted]. So far ...
2
votes
2answers
698 views

sed: how to insert a comment at the beginning of a matching line

I am attempting to write a script that will comment out the following line in /etc/sudoers every time I launch a new EC2 instance: Defaults requiretty I'm assuming the best way to do this is with ...
5
votes
3answers
14k views

How to delete all characters in one line after “]” with sed?

How to delete all characters in one line after "]" with sed ? Im trying to grep some file using cat, awk. Now my oneliner returns me something like 121.122.121.111] other characters in logs from ...
0
votes
1answer
108 views

removing malicious links from .htaccess using sed

I have a couple of hundred .htaccess files and I want to remove mallicous lines from them. On the top they all have: IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_REFERER} ...
2
votes
1answer
383 views

Sed multi-line replace over escaped strings

I'm attempting to convert a mysqldump output file to PostgreSQL compatible SQL. The issue is in dealing with escaped string values. I need to go from: VALUES('blah blah blah','second string \'with ...
2
votes
3answers
2k views

linux + sed - replace only the right most side char of string

I have linux machine red-hat 5.1 how to replace only the right single char (most side of string) example from my sed syntax (not good because its replaced both "a" chars) l echo machine1a | sed ...
3
votes
1answer
487 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
370 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 ...
1
vote
1answer
132 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 ...
0
votes
1answer
155 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
3k 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
269 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 ...
0
votes
1answer
149 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
171 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
449 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
659 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
134 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
960 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
115 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 ...
0
votes
3answers
83 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 ...
3
votes
2answers
317 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' ...
1
vote
3answers
243 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
341 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
406 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
707 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
287 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 ...