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

23
votes
8answers
46k 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 ...
22
votes
7answers
52k 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 ...
21
votes
7answers
7k 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 ...
9
votes
4answers
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.
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 ...
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 ...
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 ...
5
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
6answers
14k 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 - ...
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 ...
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
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" ...
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
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 ...
4
votes
2answers
734 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 > ...
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 ...
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 ...
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?
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 , ...
3
votes
2answers
319 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' ...
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 ...
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 ...
3
votes
1answer
497 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) ...
3
votes
2answers
243 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
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 ...
2
votes
5answers
172 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 ...
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 ...
2
votes
3answers
247 views

Replace two characters using one sed command

I'm trying to remove the = and ] characters using one sed command: # echo "A=[A]" | sed s'/[=\]]/ /g' A=[A] Something is wrong with this syntax? I Expect the following results from sed # echo ...
2
votes
2answers
1k 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 ...
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 ...
2
votes
3answers
2k views

How can I easily convert HTML special entities from a standard input stream in Linux?

CentOS Is there an easy way to convert HTML special entities from a data stream? I'm passing data to a bash script and sometimes that data includes special entities. For example: "test" ...
2
votes
4answers
2k views

How to escape “/” in a sed command in Puppet script?

In a config file, I'm trying to replace PREFIX=/jenkins with, say, PREFIX=/foobar. On the (bash) command line, this works fine: sed -i.bak s/PREFIX=\\/jenkins/PREFIX=\\/foobar/g /etc/default/jenkins ...
2
votes
3answers
175 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 ...
2
votes
3answers
159 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 ...
2
votes
3answers
3k 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 ...
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 ...
2
votes
1answer
9k views

sed replace all tabs and spaces with a single space

I got a string like the following: test.de. 1547 IN SOA ns1.test.de. dnsmaster.test.de. 2012090701 900 1000 6000 600 now I want to replace all the tabs/spaces inbetween the ...
2
votes
2answers
721 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 ...
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
2
votes
2answers
681 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
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
157 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
135 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 ...
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: ...
2
votes
3answers
400 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 : ...
2
votes
1answer
78 views

How does this sed command work?

I need to print text between two text fragments. I've found such example, that does exactly what I want, but I don't understand how it's done. Googling is difficult because command does not contain ...
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
224 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 = ( ...
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 ...
2
votes
1answer
469 views

How to remove malware code from javascript file using sed

I found the following two different pattern in some hacked javascript files. <!--2d3965--> some code <!--/2d3965--> /*2d3965*/ some code /*/2d3965*/ I am able to remove the first ...