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

learn more… | top users | synonyms

0
votes
3answers
568 views

Match and remove first and second pattern within xml tags

How can I match and remove first and second pattern within xml tags using sed or awk? Here is the example <data>A78-1-1134-HI-1</data> <data>T78-12-1346-AG-2</data> ...
2
votes
3answers
189 views

Using sed to change output format

How can I use sed to change the output format of a text file? My text file contains and diplays this when I call cat: 9/27/2002 9/28/2002 10/1/2002 10/2/2002 10/10/2002 10/11/2002 12/29/2002 ...
0
votes
1answer
190 views

Replace string with another string shell script

I have a file in the format: "data","data","data",data". Now if data has a " in it, then my parser cannot parse the file. So I want to use sed to replace " with """ but not where it sees "," as that ...
2
votes
1answer
147 views

What does `-e` option in sed do?

I am trying to understand a shell script that uses sed. I found that there were some places where sed was invoked with the -e option. I tried to see the man page and it just mentions, -e command ...
0
votes
2answers
86 views

Deleting all word occurences with sed preserving linefeed

I'm trying to delete a word's all occurences in a text file with sed. I have this file f1: alma a fa alatt nyari piros alma and I'd like to delete all occurences of "alma". I use the ...
-1
votes
2answers
126 views

Replace all numbers following a specific string with another number using sed or awk

I have tried several things but got no luck. I have an input file that has a lot of fields like this one weight=0.123456 mixed with other fields. I want to multiply all such weights by a factor, say ...
0
votes
3answers
534 views

Removing first line with pattern with _both_ awk and sed

Fairly easy. I'm looking for the simplest approaches in both sed and awk for removing the first line in a file that contains a specific string.
0
votes
1answer
185 views

Enable an epel repo via script?

I'm installing the Epel repo via a shell script, the repo comes by default disabled, I would like to enable it so the script can install further packages. The following install the Epel repo: yum ...
1
vote
1answer
214 views

error occur when i run awk command write in .sh file and run in cygwin terminal

i have cygwin terminal for run shell script(.sh ) file...it work good..but when i add awk command in shell script and then run Error occur /usr/bin/gawk.exe: error while loading shared libraries: ...
1
vote
2answers
318 views

Skype: Decode time stamps

I'm trying to extract the chat history between myself and my SO on Skype for OSX. I've managed to pull out the information and strip out the unnecessary XML formatting with the following command: ...
3
votes
5answers
2k views

Using sed to remove digits and white space from a string

I am trying to remove the first occurence of digit(s), the dot, the second occurence of digit(s) and the space before the word. I have come up with this regex: sed 's/^[0-9]\+.[0-9]\+\s//' input.txt ...
1
vote
1answer
88 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
243 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
574 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
195 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
495 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
474 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
333 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
617 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
4k 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
271 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
637 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
371 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
1k 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
72 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
244 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
946 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
371 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
359 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&#8482; ...
1
vote
0answers
111 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
708 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
555 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
117 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
4k 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
90 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
6k 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
162 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
2k 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
174 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
158 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
852 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
150 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
247 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. ...