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

learn more… | top users | synonyms

-4
votes
1answer
28 views

String replacement using sed [closed]

Searching and replacing a string in a file. Input file name - Input.txt DATETIMEOFFSET(20) datetimeoffset(99) DatetimeOffset(10) lots of data1 lots of data2 datetimeoffset(45) Output File name - ...
2
votes
2answers
176 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
26 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
8 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
37 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
24 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 ...
0
votes
1answer
21 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
27 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 (.*) ...
0
votes
1answer
20 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
38 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
1answer
71 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 ...
2
votes
3answers
49 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 ...
0
votes
1answer
23 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 ...
0
votes
0answers
33 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
44 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
81 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 ...
0
votes
0answers
124 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
114 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
60 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 ...
0
votes
2answers
66 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 ...
2
votes
2answers
59 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 ...
0
votes
2answers
33 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
35 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
50 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
42 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
28 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 ...
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 . ...
2
votes
1answer
20 views

How to substitute all occurrences after a certain number with sed in OS X

I am trying to modify a bad .csv file, where the last 'column' is broken into a different number of columns due to extra , characters. I want to use sed to keep the first 4 commas, and replace the ...
0
votes
1answer
16 views

sed adds characters where it shouldn't add

I have the following line (in a file called 1atp.pdb: MASTER 421 1 5 16 9 0 12 6 3070 2 66 29 And I'm using sed: grep MASTER 1atp.pdb | sed 's/[0-9]*/xddddd/' ...
0
votes
0answers
102 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 ...
0
votes
0answers
36 views

Multiple replace - using sed or awk

I have a code snippet like below CREATE TABLE TABLE1( ID integer NOT NULL, ROW_CREATED varchar (26) NULL, BATCH_LOG_ID integer NULL, TRANSACTION_TYPE varchar(5) NULL, PARTITION_COL integer ...
1
vote
1answer
19 views

SED/AWK/PERL(GNU userland) - how to substitute pattern A but not pattern B?

First, I am using GNU userland so you can assume I use Bash, GNU coreutils... I have a HTML and I want to change all href="foobarz" into href="" However, I don't want to change any line ...
1
vote
2answers
39 views

How to make sed print to the end of line from socat

I have a server which sends data in a UDP Broadcast on port 10552. The data is 7 numbers separated by commas as so. 5.351204,0.001968,-0.000473,-0.999222,0.000451,0.001455,1.084310 I fetch this ...
1
vote
1answer
12 views

Cygwin: during sed operation changes are not save

While I'm using sed I'm able to see correct results in terminal but in file changes are not visible. I used following comand: sed -e 's/MN2/MN9/g' 01_valid.txt on terminal screen I see changes in ...
0
votes
2answers
200 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: ...
0
votes
2answers
52 views

Append text to lines between two patterns every time they appear in a file

This will be a rather hard one, i guess. I have to fiddle around with inline documentation that is extracted into html files to be used as online documentation, but these parts of the files should be ...
0
votes
2answers
40 views

How to make a sed command to trim whitespace from the end of a string or normalize whitespace in the string?

I have some data like the following "brand": "Some brand name ", "otherbrand": "Something else ", "brand":"Some third way" although a little bit more unstructured like that, however one ...
0
votes
1answer
40 views

sed regex pattern matched greedy although it should not

I stumbled upon a behaviour I can not explain, hope some of you guys can help me out. I try to generate a sort of documentation from a bigger Ant project, as such I use sed to filter the information ...
2
votes
1answer
24 views

Prepending a ‘.’ to each domain name in a list but skip raw IP addresses

We are starting a new proxy server at work and have a list of domains that are to be blocked; the list is downloaded from an external site. To place them in Squid format we have to add a . to the ...
1
vote
1answer
96 views

piping tail -f into sed or awk

There is another question which is nearly the same, but none of the suggestions from its answer works for me: Piping tail -f into awk I'm trying to tail -f a logfile but want to replace \r with \n ...
0
votes
1answer
34 views

Removing lines in text document that end the same

We have a script that downloads a list of domains for our squid box to block, but we keep getting warnings like the following: 2015/03/02 17:08:47| WARNING: You should probably remove '.artnau.com' ...
0
votes
2answers
58 views

How do I print the line only with the last occurrence of a regex?

I have a (large) file that has multiple occurrences of the expression SCF Done and I am (for now) only interested in the last of these lines. Currently I am using a piped command: sed -n '/SCF ...
0
votes
2answers
32 views

Sort on ID, then sort on date, then remove lines which have the older date?

I have a couple of tab delimited files. Each file is structured like so: ID Title Rating Date_Rated What I want to do is merge all these files into one, ...
0
votes
1answer
49 views

Escape string input to sed

I'm having some problems with replacing a string in a file using sed with a string that contains newlines. The following will fail completely. I assume I've got to escape the replace_with string, but ...
0
votes
1answer
53 views

How to extract a substring and add it to original string with sed?

I am trying to write an sh script witch receives a string as input, extracts a particular substring and adds it after an specified expression to the input string. I tried a lot with sed -i'N ... but ...
1
vote
1answer
40 views

How to specify a sed expression to remove non-printing octal characters from a text file

I am new to sed and am cleaning up a very large file. The cleaned document looks right, but when I read it into my R, it shows that each line is appended with \016\t at the end of each line. I have ...
0
votes
0answers
78 views

Copy huge file skipping first line using dd in Linux

I was trying to copy the content of a huge file (10GB) to another skipping the first line (as in head -n1). I tried multiple ways of head, tail, awk and sed. Settled on using tail -n+2 > ./xab.1 ...
0
votes
2answers
256 views

use sed to replace part of a string

I am planning to replace certain strings in a file; so I am using sed. I would like to have the string replaced, while instead, sed read the string and append the text in the middle of the string. ...
3
votes
1answer
68 views

How do I prepend a string to program output without waiting for the whole line?

I have a script that runs a command on a remote server using SSH. I want to prepend the string Remote: to every line of the output, but I don't want each line to be delayed until the whole line is ...
0
votes
1answer
42 views

Replace with sed a tag value under a specific section when matching a line

I would like to change a line when another line matchs under a section of a file using the sed command (or awk). Here is an exemple of the file : Extract of MyFic.txt : <PlayList> ... ...