Tagged Questions

"sed" (stands for stream editor) is a Unix utility that parses and transforms text files. It implements a fairly basic programming language to perform the transformations, but is in fact Turing-complete. Sed on Wikipedia

learn more… | top users | synonyms

0
votes
0answers
17 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
64 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
33 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 ...
1
vote
2answers
76 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 ...
5
votes
2answers
84 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
17 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
72 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, ...
0
votes
1answer
53 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
68 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
39 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
85 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
49 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
41 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
108 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
70 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 ...
0
votes
2answers
52 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
21 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
81 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
107 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
43 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 ...
3
votes
4answers
196 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
77 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
78 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
51 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 ...
2
votes
4answers
381 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 ...
0
votes
1answer
54 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? ...
2
votes
2answers
78 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
91 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
87 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
1
vote
5answers
175 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
64 views

Find/SED keeps ignoring some hidden files

Is there a way to ensure find/sed include hidden files during processing?
0
votes
1answer
89 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
52 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 ...
5
votes
2answers
133 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
78 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
205 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 ...
0
votes
2answers
198 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
110 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
2answers
123 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
100 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 ...
1
vote
2answers
66 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 ...
2
votes
2answers
245 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
3answers
111 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
155 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
52 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
131 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
99 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 ...
0
votes
3answers
77 views

Using SED to join 2 fields in CSV and add them at the end of the line

I have a SED problem beyond my knowledge. I have a solar plant that generates CSV files in the format 2012-01-08;00:00;171,297;0,000; 2012-01-08;00:05;171,297;0,000; ...
0
votes
2answers
45 views

Getting values using sed

I am running a script whose output is: Circuit Packets/Bytes Sent Packets/Bytes Received 2/1 vlan-id 1005 11589119559 14650974869 ...
2
votes
3answers
134 views

Hexadecimal to Decimal conversion in Bash

This is the current output in a text file 1 3.491136 C1 00 08 00 DD 92 01 FF 2 3.560963 C1 00 08 00 DD 92 01 FF 3 3.600959 C1 00 08 00 DD 92 01 FF 4 ...

1 2 3 4