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

learn more… | top users | synonyms

1
vote
1answer
197 views

create multiple files from single text file based on headings

I have what I think is a really simple problem to solve (preferably with OS X / *nix terminal tools rather than windows command line). I have a manuscript formatted in markdown with # (H1) denoting ...
0
votes
1answer
298 views

Pattern matching gnmap fields with SED

I am testing the regex needed for creating field extraction with Splunk for nmap and think I might be close... Example full line: Host: 10.0.0.1 (host) Ports: 21/open|filtered/tcp//ftp///, ...
2
votes
3answers
360 views

How to substitute multiple lines between delimiters

Given the text example: .... text ,.. {{{python string1 = 'abcde' string2 = '12345' print(string1[[1:3]]) print(string2[[:-1]]) }}} .... text ,.. The [[ and ]] also appear outside of {{{ too. ...
1
vote
1answer
519 views

Find/replace underscored words to camelCase words using regex?

I have a ton of text files that are tagged with underscore-connected words like @some_text, but I would like to convert those to tags in camel case, like @someText. How can I use regex (either in vim ...
8
votes
5answers
13k views

How to get the pid of a running process using a single command that parse the output of ps?

I am looking for a single line that does return the pid of a running process. Currently I have: ps -A -o pid,cmd|grep xxx|head -n 1 And this returns the fist pid, command. I need only the first ...
2
votes
2answers
2k views

perl - translate sed to perl

The following command work fine on Solaris ( delete line only if last character is ":" ) sed -e '/:$/d' < foo > foo.new how to do the same in perl ? ( the reason for that because I not want ...
14
votes
4answers
3k 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 ...
1
vote
1answer
2k views

How can I use sed to modify a line of a configuration file?

My configuration file has the following format [general] setting1=true setting2=value2 [ssl] setting1=sadfsdf setting2=sdfadsfkljasdf How would I change setting 1's value to false? If I could just ...
1
vote
3answers
393 views

sed: replace each occurence of 4 spaces (at beginning of a line) with 2 spaces

Say I have this (puppet) file with an indentation of 4 spaces (I have a bunch of them that I have to process): # init.pp class hardwareid ( $package_name = $hardwareid::params::package_name, ...
2
votes
1answer
2k views

Add character at certain position in line

I've encountered the following problem: I need to add space at certain position in each line, to transform data from ATOM 1 HT1 GLY 5 10.346 30.927 130.252 0.00 0.00 to (by adding ...
1
vote
3answers
706 views

How do you parse out words from a file?

Hi let's say I have a file that looks like this <jack, john. ................ ,joe ..........Jen.. >Tom Edwa4rd 4Tim Richard How do I turn this into a clean list like jack John joe Jen Tom ...
1
vote
1answer
1k views

Replace a block of numbers in sed

I've been fiddling with this for a while now and can't seem to figure it out. What I'm trying to do is replace all numbers in a file with a single #. Sounds simple, and it should be, but I can't get ...
1
vote
1answer
348 views

How to convert HTML tags to RTF or any rich format text from the Linux command line

How can I convert HTML tags to rtRTF or any rich format text using sed or any linux command-line tool? I've achieved to strip them with sed 's/<[^>]*>//g', but I need the ...
1
vote
1answer
1k views

I want to get a count of unique entries in the Apache error logs on

When viewing Apache's log files there are a lot of error message repeated. I would like to find out which error messages are most frequent and which are unique. I would like a simple script that can ...
1
vote
1answer
138 views

Why is xkvbd eating newlines when I it is fed from xsel?

I have this script that I assign t oa keyboard shortcut to simulate pasting through middle click: #!/bin/bash aa=0 for randstring in `xsel` do if [[ "$randstring" =~ [ěščřžýáíéúůóťďň] ]] then ...
0
votes
1answer
1k views

Parsing out specific URLs from local html file

I want to parse out certain URLs from a saved html-file with a simple bash-script/command, so i can download them via wget laters. What i have so far is: awk 'BEGIN{ RS="<a *href *= *\""} NR>2 ...
1
vote
2answers
556 views

Find and hide file extension

I am trying to find all files that have the same filename (excluding the file extension) that occur 3 times. I also need the full path to the file. What I have currently is #get file without ...
2
votes
2answers
896 views

How to use verbatim strings in sed?

E.g., sed 's/string/ /g' where string="a\c:ti]\']x""/\//:`~$%#^&"' That is how to pass the string to sed literally rather than as an interpreted regex pattern? I'm going to use this with ...
0
votes
1answer
98 views

Replace Certain Elements in a Path with a Tag

I want to modify paths with a certain pattern. For example ./foo/1023023/43655345/bar/ becomes ./foo/_dir_/_dir_/bar/ The pattern is always preceded by /foo/ followed by 2 directories that have ...
0
votes
3answers
449 views

Parse and remove parts of strings between delimiters

I would like to go through a file and remove certain sequences in between delimiters. For example drw---- 00000000 11111111 0 ./a/ drw---- 00000000 11111111 0 ./b/ d------ 00000000 ...
0
votes
2answers
536 views

“sed” regex help: Replacing characters

I want to change characters in a XML file by using sed. The input looks like this: <!-- Input --> <root> <tree foo="abcd" bar="abccdcd" /> <dontTouch foo="asd" bar="abc" ...
1
vote
2answers
107 views

Move specific character in sed

I would like to process a file that contains a specific character in the middle of some words and move it to the beggining of that word. It could also appear at the beggining of a word, but in that ...
4
votes
4answers
4k views

Print back-reference in regular expression

I was hoping for a way to make sed replace the entire line with the replacement (rather than just the match) so I could do something like this: sed -e "/$some_complex_regex_with_a_backref/\1/" and ...
0
votes
3answers
615 views

Inserting string from xargs into another string

Say I have some command that outputs a bunch of strings. The output from this command could look something like: ... foo bar blargh ... Say I have some set string myString$Blah I want to insert ...
0
votes
3answers
273 views

How to use sed to remove certain text base on regular expression

I got a text file with contents like below 2012/03/15 : "Password":"@#4JF9u92r","Name":"John" I wish to use sed to change the above to 2012/03/15 : "Password":"XXX","Name":"John" I have tried ...
-1
votes
2answers
543 views

Getting rid of dashes in a file with sed

I'd like to use the sed command to get rid of some dashes in a string (inside a file), i.e., the file has a line that says: TEXT=abcdef-lalala-someText-yahoo After the sed execution, that line ...
3
votes
4answers
2k views

How to remove lines from large text file using bash

I got a huge text file (log file) in my CentOS which I would like to remove top part of, probably couple of thousand lines each day. (Or probably just split into two) I have search this site and ...
1
vote
4answers
228 views

sed -e “s/-.*$//”

What does the -.*$/ in this command mean? Please help me decipher this. echo -n full | sed -e "s/-.*$//" I know what sed does and all that, I just want to know what this -.*$ part is.
0
votes
1answer
218 views

Why does sed cause git to consider the entire file rewritten?

Using Cygwin on Win7x32, when I use sed to replace some values in a file, git then considers the entire file to be completely rewritten (i.e., 500 insertions, 500 deletions). What's going on here? ...
3
votes
2answers
392 views

Flatten a folder structure to a file name in Bash

I'm trying to convert files from this structure: foldera/folderb/filec.png to: foldera_folderb_filec.png I'm halfway there: find . -type f -name "*.png" | sed 's@^./@@g;s@/@-@g' which ...
1
vote
1answer
301 views

Batch search and replace file path

So I've got lots of m3u playlists created on my Windows machine inside a folder with file paths to tracks as: D:\path-of-mp3 So first I want to replace all the \ with / and then D: with ...
1
vote
3answers
255 views

Split numbers using stream editor (sed)

I want to insert periods as thousands separators using sed. How can I do that? Sample imput/output: 29371923471239 -> 29.371.923.471.239
2
votes
5answers
8k views

sed - perform only first (nth) matched replacement?

Consider I have the following file: echo "1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 " > ztest Here I'd like to change only the first 1 into 5 and leave everything else intact. I know sed has a quit ...
1
vote
2answers
233 views

Find/SED keeps ignoring some hidden files

Is there a way to ensure find/sed include hidden files during processing?
0
votes
1answer
579 views

How to insert thousand separator with `sed`?

I want to insert thousand separator into a number sequence with sed and this ugly RE sed -e :a -e 's/\(.*[0-9]\)\(\([0-9]\{3\}\)\(,[0-9]\{3\}\)*\(\.[0-9]*\)\)/\1,\2/;ta' [filename]. Is there a more ...
1
vote
1answer
118 views

Delete newlines using Stream editor (sed)

I need to write a sed script that places the actual text of the subtitles in a srt file on a single line. If this text originally was split over multiple lines, the line break and possible ...
8
votes
3answers
2k views

Cygwin bash sed locks my files

When I change files in cygwin bash with the sed command, the file gets locked. Reproduce: Open cmd and cd to non-user directory (f.e. temp) echo aaa > test.txt Open in texteditor, add line, try ...
1
vote
2answers
228 views

replace all names with an alternative using Stream editor (Sed)

I got this question on a task. Nothing works.. Can someone help me? Write a sed script that replace all names with an alternative, search for every words that: Start with a capital, Longer than ...
2
votes
3answers
1k views

awk/sed + replace only the second char with one space

please advice how to remove only the second "." character from the version number with awk I need to fit the syntax for Linux & Solaris I write the sed "s'/\./ /g'" - but this syntax ...
1
vote
2answers
6k views

Sed for windows

I am attempting to use SED for the first time. To complicate matters, i am using it in windows. I downloaded from this source. Since I don't have install privileges on my work machine I created a ...
0
votes
2answers
487 views

Delete every 3rd and 5th line except 15th line with Stream EDitor

I need to delete every 3rd and 5th line except the 15th line in a text file using sed. Has someone an idea?
0
votes
3answers
454 views

Oneliner for multiline regex s/,\n]/]/g?

Can someone provide a simple one-liner to remove certain line breaks? In vim I use %s/,\n]/]/g This should be possible with a very simple one-liner IMHO, but how?
0
votes
0answers
182 views

How can I improve or wrap my sed-script?

I instrumented a mvn build to emit profiling data, which I want to analyse later on. Therefore, I made the sed script below, to generate json-data from the profilers output. I call the script with ...
2
votes
2answers
179 views

Replaces images\(.*)“ with images/\1” in all files?

I've got a bunch of html files, and all the img tags have the slashes the wrong way! Here's an example (except it's one line in the code, split here for ease of viewing) <a ...
11
votes
6answers
3k views

Removing ANSI color codes from text stream

Examining the output from perl -e 'use Term::ANSIColor; print color "white"; print "ABC\n"; print color "reset";' in a text editor (e.g., vi) shows the following: ^[[37mABC ^[[0m How would one ...
1
vote
4answers
500 views

sed removal of whitespace

I find that sed often fails to pattern-match whitespace. Consider the following examples: echo 'A B C' | sed 's/[ \t]*//g' ABC echo -e 'A\tB\tC' | sed 's/[ \t]*//g' A B C perl ...
0
votes
1answer
435 views

Sed pattern for multiple lines

I want to remove all create table statements from a mysql script, but the statement runs over multiple lines. Like this: Create table ......NEWLINE... NEWLINE... NEWLINE....; So I tried this ...
0
votes
1answer
193 views

seq with regex, error message for mysql quotes

Is there some tool that auto quotes regex for seq? I can't figure out what I'm doing wrong. I always get this error unterminateds' command` sed -i 's/INSERT INTO `tablename.*`/INSERT INTO ...
0
votes
1answer
277 views

awk + sed + match complex string

I need useful command to match the string "/pci.../pci.../pci..../scsi..../disk..." with awk or sed? ( I need to put this command in my ksh script ) remark 1 [...] can be any string , and “pci pci ...
0
votes
1answer
663 views

sed + does not work on solaris

I try to use a sed line with a + on a Solaris machine and on a Linux machine. on Solaris sed does not remove the strings until the first number like I want: solaris:/ ROOT > echo ...