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

learn more… | top users | synonyms

1
vote
1answer
18 views

How to remove pattern containing blank space and special characters in sed

How to remove following words from a text file: DEFAULT ('') DEFAULT ((0)) DEFAULT (((1)/(1))/(1900)) DEFAULT (getdate()) I am not able to delete above four pattens using sed.
0
votes
0answers
5 views

Match a word with optional delimiters with sed, grep and PCRE [migrated]

How do I match a word with optional delimiters? Say I have a file named file a b "a" "a c and I want to match only quoted or unquoted a (I don't want to match "a). I'd like to do such match with ...
0
votes
1answer
9 views

Quotes in sed when used in bash script

I am generating sed expression in Bash script, and I am having a following problem. I want to add a space in front of each appearance of abc. This commands works as expected echo abc | sed -e ...
-1
votes
1answer
17 views

bash change strings with multiple escape characters

Hello i try to automate for example change one variable in php file . root /tmp # cat defaults.inc.php|egrep "reply_all_mode" $config['reply_all_mode'] = 0; I try to first catch this by grep ...
0
votes
2answers
42 views

How to insert lines into specific files in which a string is not present?

I'm looking for some help with a small script. I would like to search all files corresponding to /usr/local/directadmin/data/users/*/httpd.conf for the string centralized.log If the string is ...
0
votes
2answers
22 views

How can I replace a newline with its escape sequence?

Using sed to make text that contains certain characters suitable for use in string literals is straightforward: sed "s/\\\\/\\\\\\\\/g" sed "s/\\\"/\\\\\\\"/g" But how can I do something similar ...
1
vote
2answers
25 views

How to execute command and use it's result in sed correctly?

I have a config file in JSON format with following block "device" : { "name" : "MyPi", "type" : "ws2801", "output" : "/dev/spidev0.0", "rate" : 250000, ...
2
votes
2answers
9k views

How do I encrypt Samsung 840 SSD with Bitlocker?

I need help encrypting my Samsung 840 Evo with Bitlocker. Here is my hardware: Samsung Evo 840 500GB hard drive (firmware EXT0BB6Q) Asus P8z77-v motherboard (BIOS v. 2104) Asus TPM chip - purchased ...
1
vote
4answers
325 views

retrieving headers / comment blocks

I have a number of log files that look like this: /* header arbitrary number of lines */ blah blah blah blah Using simple Bash commands (preferably sed, not awk), how would I retrieve only the ...
1
vote
4answers
1k views

using sed to remove lines in a file

I have a file that looks something like this: Heading - - Completed foo - More information - Still more * Need to complete bar - Did baz (comment blah blah) *** Another - * Need to ...
2
votes
2answers
191 views

Sed command with apostrophe

sed -e 's/cluster_name: 'Test Cluster'/cluster_name: 'Test Cluster1'/' I have this error message: sed: -e expression, char 20: unterminated `s' command Please, how can i correct the sed command ...
2
votes
1answer
29 views

Recursive find-replace using sed with URLs

I have a large set of files in which I need to replace a full URL scheme. Some filenames contain spaces. After much searching and rial and error, this is the closest I've come: find /somedir -type f ...
0
votes
0answers
9 views

Mac OS X Find and Replace API

Are the Find and Replace operations under the Edit menu in Acrobat or Word simply a front end for the unix awk, sed or grep commands? Where can I find more information about what's going on underneath ...
0
votes
1answer
41 views

Edit file in-place without modifying line endings

I need to modify sources under Git version control. The sources are Visual Studio project files, which makes them native Microsoft. I want to avoid whitespace issues, including line ending games. I ...
1
vote
1answer
31 views

Remove invalid domain names with Sed

I'm having trouble writing a sed command do the following. I have a file that should only contain "valid" domain names. How I use with sed to remove any line that does not match an expression? The ...
21
votes
5answers
24k views

use of alternation “|” in sed's regex

I am using sed, GNU sed version 4.2.1. I want to use the alternation "|" symbol in a subexpression. For example : echo "blia blib bou blf" | sed 's/bl\(ia|f\)//g' should return " blib bou " but ...
3
votes
2answers
2k views

How can I use sed to alter the results of find and pass the results to cp?

In solaris, I'd like to copy all files found by the find command to a slightly different path. The following script basically executes cp for each file found by find. For example: cp ...
0
votes
2answers
295 views

sed: What does exit code 2 mean?

Case I am trying to replace all occurrences of <value>*</value> into <value>file:\\</value> in a designated file test.txt. I work on Windows and use sed I have installed with ...
0
votes
1answer
29 views

String replacement shell script on AIX

I am using AIX, and there is not an -i option available in the version of sed I am using: sed: illegal option -- i Usage: sed [-n] Script [File ...] sed [-n] [-e Script] ... [-f Script_file] ...
2
votes
1answer
28 views

Match first next word matching a given pattern using sed

I'm having trouble getting the following behaviour: input='somestring... --key1 val1 --key2 val2 --key3 val3 somestring...' output='val1' I tried using: echo $input | sed -nE 's/.*--key1 (.*) ...
20
votes
5answers
5k views

Substitution in text file **without** regular expressions

I need to substitute some text inside a text file with a replacement. Usually I would do something like sed -i 's/text/replacement/g' path/to/the/file The problem is that both text and replacement ...
0
votes
1answer
25 views

Remove version information from maven generated war file

I am trying to automate the deployment of war files that are generated by our build server using maven. I need to be able to extract the project name from the war filename so I can rename the file ...
0
votes
1answer
42 views

Piping a line of the file read with while read loop

I am trying to read each line of the file and then assign some parts of it to variables. A line itself is read as a variable so I need to process a variable input say for cat which seems to be ...
2
votes
3answers
58 views

Extract version string from filename

We have a list of filenames in file a.txt with their version string embedded in them. Eg: gson-2.1 xmlParserAPIs-2.4.0 acrobat-1.1 orai18n-mapping-12.1.0.2 jdbc-se2.0 eclipse-core-runtime-20070801 ...
2
votes
1answer
86 views

Append text to first occurrence of a pattern using sed

Say there is a text file as below: Hello world types="" Mario types="Game" What I want to do is find the first occurrence of type="" and append with word "program". I need output as: Hello world ...
27
votes
11answers
16k views

How to Remove the Last 2 Lines of a Very Large File

I have a very large file ~400G, and I need to remove the last 2 lines from it. I tried to use sed, but it ran for hours before I gave up. Is there a quick way of doing this, or am I stuck with sed?
0
votes
1answer
26 views

How can I make this SED command more portable?

I'm using the following sed command: cat version | sed -e 's/[0-9][0-9][0-9][0-9][0-9:M]*-[abp]/Ver\n/' Which normalizes like this: 4330M-p -> Ver<newline> This works fine with GNU ...
5
votes
4answers
4k views

SQL like group by and sum for text files in command line?

I have huge text files with two fields, the first is a string the second is an integer. The files are sorted by the first field. What I'd like to get in the output is one line per unique string and ...
0
votes
2answers
230 views

How can I delete the content between two tags in a large xml file (>2GB)

The File in Question is XML but I want a Shell Script to remove all the binary (Base64) encoded images that are embedded. The files are generally huge (>2GB). I want to delete everything between: ...
2
votes
3answers
520 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
0answers
36 views

Replace in file with Huge String (Argument list too long)

I have a file in which I want to replace a string with a huge string literal in the form "19209302","19209329" such 100 thousand of entries. I am using sed and I get "Argument list to long" error, ...
0
votes
1answer
57 views

How would I write this VIM command for `sed`?

I have a .csv with special characters that are wrecking an import I need to do. In VIM, I discovered away to remove the special characters with : :%s/\r//g This removes ^M from some of my broken ...
1
vote
2answers
101 views

Best way to increment numbers in one line in Linux [closed]

I have one line with lot of entries among which is also time. ('DEFAULT',17,NULL,'2014-07-14 10:30:00','Something','2014-07-14 06:30:00',1),('DEFAULT',26,NULL,'2014-07-14 ...
4
votes
3answers
6k views

How append a string at the end of all lines?

I'm trying to add a string at the end of all lines in a text file, but I have a mistake somewhere. Example: I've this in a text file: begin--fr.a2dfp.net begin--m.fr.a2dfp.net begin--mfr.a2dfp.net ...
2
votes
2answers
67 views

how to insert text at the beginning of each paragraph in bash

I have a file with multiple paragraphs separated by blank line. Technically they are not paragraphs just sections of text separated by blank line. I want to number the paragraphs so to speak by ...
13
votes
4answers
10k views

Newlines in sed on Mac OS X

I find that \n doesn't work in sed under Mac OS X. Specifically, say I want to break the words separated by a single space into lines: # input foo bar I use, echo "foo bar" | sed 's/ /\n/' But ...
1
vote
2answers
471 views

Change names in a column in bash

I have a tab-separated file in Linux that looks like this ~$ head list.tab "x" "1" "FUHGF.jnf.m22-1" "2" "HDFHFEY.gfs.d2-1" "3" "KJFGJF.fr.md2-1" "4" "SDFSDIB.gfd.rtl2-1" "5" "FGJFGOB.hgd.k2-5" "6" ...
0
votes
0answers
134 views

Removing special characters (spaces, newlines, tabs) from a text file

I have a flat file (1252 ANSI-Latin 1 encoding) that I wrote out from querying a third party's SQL database that has within it extraneous characters. To make it easier to reformat, I am writing it ...
2
votes
2answers
125 views

How to remove string following a specific word

I am trying to remove string starting with a specific word in my manifest file. The file containing lines looks like: <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" ...
1
vote
1answer
75 views

How do I edit an xmlTV file using sed (or a similar tool)?

I have an xmlTV file that looks like this: <channel id="10125.dvb.guide" <!-- number="62" type="0x1" flags="0xf" bouquet="4097" region="4a" sid="10125" -->> <display-name>ITV ...
3
votes
1answer
10k views

Multi-Line Sed Replace

Consider the following text (incidentally, part of a MySQL dump): CREATE TABLE `table` ( `id` int(10) NOT NULL auto_increment, `name` varchar(100) NOT NULL default '', `description` text NOT ...
0
votes
2answers
85 views

grep and sed with pipe from tail -f appears to be caching

I am trying to get a working system to monitor special logs. I usually just want a very specific pattern which I extract using grep and a pipe from tail -f. I have noticed that grep does not output ...
0
votes
2answers
34 views

Why am I getting mv errors with this sed command?

Given the following directory: [~/test]find . . ./something_else.txt ./univision.rbw ./something_else.rb ./testtest ./testtest/weewee.rb ./testtest/weewee.txt ./univision.rb Running the following ...
2
votes
1answer
39 views

grep -l output filenames with spaces

I want to loop over files with for f in `grep -rsl "foo" . `: do sed -i -- "s/foo/bar/g" $f; done; But since filenames contain spaces, a filename is split whenever a space is found. How can I ...
0
votes
0answers
63 views

Backrefence syntax in powershell's sed

How do I back reference a capture group in powershell's sed? I can't seem to find the syntax for it. IE I expect echo "hello" | sed "s|(h)ello|world\1|" to output worldh, but instead I get the ...
0
votes
1answer
47 views

Remove a specific string common in multiple lines in a CSV file using shell script

I have a CSV file which contains 65000 lines (size approximately 28 MB). On each of the lines they have a path in the beginning in the format of: c:\abc\bcd\def\123\456. Now let's say the path ...
1
vote
1answer
29 views

How to serach for a line which contains specific string in Bash?

I've got a file which contains some amount of lines, I want to look for a specific string, and if the file contains it, then I want to print a different line from the same file. for example, let's ...
15
votes
4answers
11k views

How to use sed to remove null bytes?

What is the sed incantation to remove null bytes from a file? I'm trying: s/\000//g but that is stripping out strings of zeroes. s/\x00//g seems to have no effect. I'm trying to do this in a ...
1
vote
2answers
19 views

How to add the filepath to a specified line of a file using bash script?

I have the following bash code: echo "Enter an input path" read -e input_path OLDTEXT="\put(0,0){\includegraphics{/" NEWTEXT="\put(0,0){\includegraphics{$input_path/" find . ...
0
votes
0answers
141 views

sed gives “illegal byte sequence” error when trying to replace a character

I am using the “Terminal” in Mac OS X 10.10 (Yosemite) and I am trying to delete all occurrences of a from a file, by using sed: sed 's/a//g' file Which gives me the following error: sed: RE ...