Tagged Questions

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

0
votes
1answer
152 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
979 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
215 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
3answers
241 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 ...
2
votes
2answers
672 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
12k 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
106 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
2answers
152 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
1answer
375 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
476 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
364 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
153 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
265 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
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 ...
20
votes
7answers
6k 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
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
442 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
634 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
945 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 ...
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' ...
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 ...
6
votes
4answers
5k 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
241 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
339 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
397 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
695 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
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
1answer
280 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
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 ...
2
votes
4answers
330 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
84 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
95 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
169 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
5k 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
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
458 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
256 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
147 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
860 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" ...
0
votes
2answers
208 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 ...