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
2answers
33 views

Why does this bash command sometimes return a blank string?

I have the following line to generate a random number: head -c 3 /dev/urandom | hexdump | sed -e 's/[0 a-z]//g' | head -c 1 This works fine but sometimes (very few) it returns a new line. Does ...
0
votes
1answer
33 views

Invalidating email addresses from sql dump before import

Synopsis I would like to import production data into the development environment so testing can be done in an almost accurate way. Of course I need to invalidate e-mail addresses as I don't want ...
0
votes
2answers
27 views

Tinydns data file change ip with bash

I am using tinydns and need to dynamicly change some ip in data file. I want to use bash script for it. For example data file: +sub1.example.org:282.196.222.245:14400 ...
1
vote
1answer
30 views

Sed to replace/merge line in etc/group

I have a list of users from 1 command - getent group ldap-group|cut -c 32-700 This gives me a list of users in the form user1,user2,user3... I would like to insert this into /etc/group under ...
3
votes
2answers
414 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
61 views

iptables arp compare and execute

EXAMPLE: iptables :internet - [0:0] -A internet -m mac --mac-source 48:5D:60:FC:29:B0 -j RETURN COMMIT [root@localhost:~ ] $ arp Address HWtype HWaddress Flags Mask ...
1
vote
1answer
58 views

Wrangling sed to find and reformat login date (or, how to kill idle mosh-server processes)

I have an old method of killing idle mosh-server processes, which doesn't work on my new VPS. Here's the old method, which I run in root's crontab to clean up mosh processes that have been idle for ...
1
vote
2answers
62 views

Long string insertion with sed

I am trying to use this expression to insert the contents of one text file into another after a give string. This is a simple bash script: TEXT=`cat file1.txt` sed -i "/teststring/a \ ...
0
votes
1answer
46 views

sed -i does not work when run with sudo

The file I want to modify belongs to root. I want to change this file with a sudo-er sudo sed -i 's/Accept .* LC_\*$/& GIT_*/' /etc/ssh/sshd_config (trying to append GIT_* to the Accept sshd ...
2
votes
3answers
962 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
1answer
342 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 ...
1
vote
2answers
153 views

Deleting inserted content in multiple files on linux server

I often have problem with sites that get hacked. Usualy they end up with inserted script in different files. Is there a way, on linux, to search for this content and automaticaly delte it ? Usualy ...
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
1answer
61 views

sed inline replacement and without having to create a file [closed]

I'm trying to do a replacement inline in a configuration file after defore deploying this file. I looked in the sed documentation but I can't get it working. Even with -e For now I mv into .back file ...
-1
votes
1answer
113 views

sed regexp for replacing xxx in define('DB_PASSWORD', 'xxxx');?

I'm looking for a regexp to quickly replace the password inside the following wp-config file, like so: define('DB_PASSWORD', 'xxxx'); Now the config file has many defines, so it essential to only ...
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
85 views

Procmail - Replace From with text from within email

I am trying to use Procmail to filter through mail that goes to my ticket channel in WHMCS. It works fine as far as piping goes. But emails from the Zopim live chat module on the site need filtering ...
0
votes
2answers
308 views

GREP find and use SED to replace string on all files

One of our old hosted Joomla sites suffered a JavaScript injection, and im going through cleaning it up. The following code was inserted into every .php or .js file: <? #0c0896# echo " <script ...
1
vote
1answer
313 views

How do I replace specific line positions in sed?

I need to be able to use sed (or anything else) to replace a specific line position, I'm Googleing and can't find anything (yet). * UPDATE * this is what I came up so far.. sed ...
0
votes
1answer
61 views

Changing Zone files with sed

I have this dns zone file I was unable to change the resource record type A to CNAME @ IN SOA ns1.domain.com. webdev.domain.com. ( 2006080101 ; serial 8H ; refresh 2H ...
20
votes
3answers
36k 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
2answers
141 views

sed + how to remove the last string after specific character

how to remove the last string after "." character include the "." character itself implementation can be with sed under Linux/Solaris operation system example of IP address before change ...
-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> ...
2
votes
3answers
383 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 : ...
1
vote
2answers
46 views

I want to filter out two lines from the output of a program [closed]

I have a command that outputs a bunch of data, but I only want two lines. Grep doesn't work because the lines I want are not next to one another. I can't seem to figure out sed... Help please. :) ...
2
votes
1answer
74 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
4answers
937 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
90 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 ...
-1
votes
2answers
297 views

linux/solaris insert date & time at the beginning of each line in file

I want to add date & time at the begging of each line in some file I used sed in order to add the date & time before each line in file please advice what I need to update in my sed in order ...
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 // ...
0
votes
1answer
141 views

Regex matching specific details if first match exists, multiline

I'm struggling to get the correct regex to match specifically 'Contact' and 'User-Agent' only if the 'Contact' address matches 10.0.x.x in ~70GB of SIP messages. The SIP message will always contain a ...
0
votes
2answers
271 views

remove non-printing characters

I have a tab delimited text file. When I open the file with vi editor, I can see ^M character (in blue color). This is not part of my data. It got there because the original SQL data had carriage ...
2
votes
2answers
1k 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
111 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 . ...
9
votes
3answers
818 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.
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
3answers
511 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
150 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
152 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
876 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
230 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
68 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
232 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
176 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' ...
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?
0
votes
1answer
91 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
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 ...
1
vote
1answer
2k 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 ...
0
votes
2answers
111 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
817 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": ...