"sed" ("stream editor") is a Unix utility that parses and transforms text files.

learn more… | top users | synonyms

1
vote
1answer
83 views

Incorrect version of sed when compiling on OSX

I am trying to install crosstool-ng on OSX 10.6.8. At the configure stage, I run ./configure --prefix=/opt/cross, and I get the following output: ! ./configure --prefix=/opt/cross checking build ...
3
votes
2answers
1k views

SED: How can I print every line after first instance of string using Sed?

I have a file with a similar format... 16:28 asdfasdf 16:29 4398upte 16:30 34liuthr 16:31 34tertio How can I use SED to print out every line including and after the line with "16:30"? The result ...
1
vote
1answer
208 views

Subtract files from one another recursively between two similar directories

I'm trying to concoct a way to grab two (nearly identical) directories and show me the difference between all files in the two directories. Looking for two different things: 1- List all files ...
1
vote
1answer
1k views

How to use variables in sed on Windows?

I'm writing a batch script to automate build events on Windows, and as part of it I need to change some lines in a few files. So I'm going to use sed. But how do I use variables in sed inside a batch ...
0
votes
1answer
475 views

Grep issue (match two strings on same line)

Here I have some grep command which is not working correctly: cat file1.txt: apples Date: Sun, 24 Feb 2013 8:14:06 -0800 peaches melons cherry sky cloud green purple yellow cat file2.txt: apples ...
0
votes
3answers
185 views

Advanced sed command

I have a file (/usr/test.log) with a bunch of lines, of the form [enable/disable] [name] [stuff] For example: enable telnet max_pkt 0 max_payload 0 min_payload 1 disable_function 0 ...
1
vote
1answer
454 views

why is it true that three backslashes are needed on windows for sed replace

Refering to this question: Why is an extra \needed in cmd.exe to work with sed (MinGW msys-1.0) when \ is not a special character according to cmd /? (see last paragraph or here)? The following ...
0
votes
1answer
441 views

Multi-line find and replace across multiple files on linux

I have: Old Google analytics tracking code oldcode.txt New Google analytics tracking code newcode.txt 100+ html files *.html in one directory Is it possible to replace former with latter in all ...
2
votes
3answers
315 views

matching start of the line in cygwin regexp

I apply sed 's/^ bug*/__/' to ref bug bug ref and get ref __ __ ref The same is responded for perl, perl -ni -e 's/^ bug/__/; print'. Sample file can be downloaded ...
0
votes
1answer
575 views

Search & Replace Using Grep and Sed Command

I want to remove the weird / special characters from the bunch of text files. Here i used the following command to remove the weird characters but it gives me the error. Command : 1) grep -lri -e ...
1
vote
3answers
3k views

Bash: Find and replace text strings

I figured this would be easy, but I'm overlooking something simple: I have a text file called test. It contains, for example, the string Alfred Hitchcock. I want to replace this with Alfred\ ...
0
votes
1answer
254 views

Combining multiple data files with header while also adding a data column

I have multiple tab delimited data files that are separated by month in the format jan06.txt, feb06.txt, ..., dec07.txt. Within each file, it looks something like: Header1 Header2 Header3 ... Data1 ...
2
votes
3answers
517 views

How to replace one line for multiple lines in a file, programatically?

I have this config file I want to edit programatically. I always use sed to make small changes, but now I need to replace 1 line for multiple lines, something like this: some code # maintenance ...
8
votes
1answer
317 views

How to make sed omit not matching lines?

In the following example, sed matches lines starting with an a or a c and prints the first character of that line (a or c): $ echo "ag bh ci dj ek fl" | sed 's/\(a\|c\)./\1/' # Matches lines starting ...
1
vote
4answers
850 views

Batch renaming of files using regular expression in Unix

I have several thousand files of the form: [8-digit number]_[number I want]_S60491_I129111.dcm. I wish to remove everything except the number I want, and use that as its name. In Ruby, I can get to ...
0
votes
1answer
71 views

Why SED man -i option doesn't have description?

My Sed's man outputs this: Zero- or One- address commands = Print the current line number. a \ text Append text, which has each embedded newline preceded by a backslash. i \ ...
0
votes
4answers
228 views

How do I move a line in a file to the top from the command line?

I would like to move a path in a file to the top of the file. Each path is listed 1 per line. How do I move /someplace/2nd/ to the top using only the command line? /someplace/1st/ /someplace/2nd/ ...
2
votes
3answers
1k views

How can cat/print a file except the last 2 lines?

How can get a file, except the last (for instance) 2 lines, with standard or GNU shell tools? (bash, tail, cat and so on.)
3
votes
4answers
847 views

How to replace a list of strings by another list

I have a file which has (many) strings I'd like to replace, so I thought about using a simple command like: sed 's/string1/string2/g' file1 > out However, there are too many strings for that ...
3
votes
2answers
357 views

Unix HP-UX ksh recursive find and replace

I am trying to do a recursive find and replace in HP-UX and am missing something. What I have at the moment: find . -name "*.java" | xargs sed 's/foo/bar/g' I know the problem is that it's not ...
0
votes
2answers
345 views

sed regex remove special characters

I have a file with several strings that come from an HTML formated text, so they have some HTML sequences that doesn't look good in a console interface. Here's an example: Text1™ ...
1
vote
0answers
107 views

sed without regex

I am using GNU SED for find and replace functionality on large files(upto 2GB). Find and replace characters can contain any characters, hence I want find and replace parameters to be treated as plain ...
1
vote
1answer
622 views

Remove characters from column 'n' until end-line

I have a huge text file. This file has many lines and most of them have more that N characters before end-line. How can I use sed to truncate lines from Nth character until the end of line? Note: ...
0
votes
1answer
518 views

replace long text with special characters with sed

I am using sed in unix to replace some text with special characters in a file. I google it and find the following command sed 's/from/to/g' file.txt here 'from' is the original text being replaced, ...
0
votes
4answers
115 views

Simple script parsing text, what is wrong here?

I'm a big user of https://www.grc.com/passwords.htm to get strong passwords. However, having to go to the site and manually copy the password every time gets old fast, so I decided to do a little ...
0
votes
1answer
2k views

How to append text to a specific lines in a file using shell script?

I have a text file (file.txt) having content something like: foo1 3464 foo2 3696 foo3 4562 It contains the process and respective PID. Using shell script, I want to append a string (running/not ...
3
votes
3answers
68 views

merge pieces of file together

I have a directory tree of files I need to loop through and reformat the lines. can I do this with sed with some combination of find? for each file, I'll need to adjust the text in the file from ...
7
votes
2answers
2k views

Edit first line of large text file

I have a huge text file, far too big for the whole thing to be paged into memory. All I need to do with this text file is edit the first line (its a CSV file and I need to alter the titles). Is there ...
2
votes
2answers
3k views

use sed to replace nbsp, 160, Hex 00a0, Octal 240, non-breaking space

I am having some problems with config files which have the non-breaking space chars in them. How should I specify that character with sed so I can replace it with a space. sed -n 's/ / /g' ...
0
votes
1answer
88 views

Get original sed back on my Mac

I replaced sed with the GNU version on my Mac. I thought I made a backup of the original (BSD version), but apparently I didn't, and now I need it back. Can someone help me?
2
votes
4answers
5k views

Using sed get substring between two double quotes

I have a file xyz... rsync: "/home/path/to/file": Permission denied (13) rsync: "/home/path/to/file1": Permission denied (13) rsync: "/home/path/to/file2": Permission denied (13) rsync: ...
1
vote
2answers
155 views

Parsing two input files and comparing line existence

I need to take two text files and check to see if a line that exists in File A doesn't exist anywhere in File B. Each line in File A that does not exist in File B should be copied to an output log. ...
1
vote
2answers
1k views

sed regex digits

I'm trying to use sed to substitute all the patterns with digits followed immediately by a dot (such as 3., 355.) by an empty string. So I try sed 's/\d+\.//g' file.txt But it doesn't work. Why is ...
2
votes
1answer
170 views

Delete first lines from a Unicode html file

I have an HTML file that is in UTF-8 format and I want to remove the first five lines from it. I've tried using sed but it doesn't work in this case: sed "1,5d" Result.html>small2 It actually ...
2
votes
1answer
150 views

Grep the whole body of a function

Supposing I know that someFile.php contains the definition for someFunction(). How would I go about displaying the whole body of the function in stdout? If I know that the body is 10 lines long then I ...
2
votes
4answers
775 views

How do you remove all occurrences of values in one list from another list?

I have a list of symbols such as... wer sfe efo How do I remove all instances of these (unique) symbols from another list of (non-unique) symbols? So in the following list, the lines starting ...
3
votes
1answer
147 views

Parse by Control Characters

I am trying to parse the output of a command that expects to be writing to the screen. It has data separated by move-to-origin control sequences (for the VT220, ESC[1;1H). I only need the last part ...
2
votes
2answers
233 views

Is there a UNIX command that can replace an XML element? (Like a sed for an XPath?)

Is there a pipe-friendly program that takes: An XML document An XPath expression indicating the target element(s) The desired replacement ? Something like sed but knowledgeable about XML ...
1
vote
0answers
14 views

FTP over'd image files with transfer-type: ASCII; possible to revert? [duplicate]

Possible Duplicate: Recovering corrupted files uploaded in wrong FTP mode undo effect of ASCII ftp transfer I've downloaded hundreds of files from a Drupal install using FileZilla. ...
0
votes
2answers
707 views

using sed to print next line after match

I came across various examples on printing next line after a match, that use awk and sed. I'm using it in my code and it works fine. Now I want to use a variable instead of a hardcoded value for the ...
3
votes
1answer
737 views

grep, xargs, sed to clean up PHP eval hack

I'm attempting to use the commands found on http://devilsworkshop.org/tutorial/remove-evalbase64decode-malicious-code-grep-sed-commands-files-linux-server/55587/ to clean up a PHP eval based hack on a ...
2
votes
1answer
199 views

sed stdin faster than reading from file?

I'm trying to determine if sed is faster reading from stdin (with shell redirection < ) or by specifying the file from which sed should read. I didn't find a definitive answer on Google. Which is ...
0
votes
1answer
101 views

Can not understand this script

Can someone help me understand this script? It is from sysconf_add and I am new to scripting. I need to do something similar. function add_word() { local word=$1 local word_quoted=$2 ...
0
votes
1answer
354 views

remove white space before delimiter with sed

I have data of the following format that I want to input into LibreOffice Calc: data | num | num | num | num For some reason LibreOffice does not think the string "3214 " is a number by default ...
0
votes
1answer
1k views

solaris 10 + display 2 lines after match by grep?

how to match string , and display the two line under the string for example ( I want to match the "manufacture" string and display the two lines after cat ima.conf # the manufacturer or driver ...
1
vote
2answers
1k views

How to extract e-mail or domain from mixed data file in linux

File content: 17541 From Email subscription@test.com Inbound Policy Manager Envelope Analysis Profiler 17541 From Email subscription@yahoo.com Inbound Policy Manager ...
-1
votes
1answer
86 views

using sed, how to change the text on line seven to read seventh?

using sed, how to change the text on line seven to read seventh? Steve Blenheim:238-923-7366:95 Latham Lane, Easton, PA 83755:11/12/56:20300 Betty Boop:245-836-8357:635 Cutesy Lane, Hollywood, CA ...
12
votes
5answers
2k views

How to mass prepend text to file names?

Lets say I have a directory full of .md files all named various things. Lets say I wanted to prepend "text" to the front of each file name. So for example: file a.md, b.md, and c.md would become test ...
1
vote
5answers
2k views

How to grep column after second pipe

Example: 3|100|test@test.com|0|0|6:1,10,11,12,13,2,3,4,5,6,9|7:1,10,11,13,16,2,4,5,6,9| Expected view after grep: test@test.com
3
votes
2answers
888 views

sed Command on BusyBox expects different syntax?

I hope I phrased the question correct. I have a script that makes use of 'sed' a lot. It works great on my ubuntu with the GNU 'sed'. But when I try to run it on BusyBox it fails. Is there a way to ...