sed is a command-line stream editor for filtering and transforming text.

learn more… | top users | synonyms

2
votes
2answers
137 views

SED on Mac OS X

I'm using a MacBook Pro and I want to find and replace a given word with another with sed command, but it makes no changes. What is the problem? sed 's/\<cat\>/dog/g' tt.txt
2
votes
2answers
209 views

Compare set of values from two files and print the output in third file in awk

Hi friends i have problem with comparing two files.I'll try my best to explain.I have two file f1 and f2 which i have to compare on basis of two sets Parameter(p) and Value(v). Basically f1 contains ...
1
vote
2answers
98 views

Using sed to replace javascript code in multiple files

I need to replace an old google analytics code with the new universal tracking code in lots of static html files. The old code looks like this: _uacct = "UA-XXXXXX-X"; urchinTracker(); The new code ...
1
vote
2answers
146 views

Removing special chars from file and maintain field separator

I've been able to remove all special characters from a fixed length file which appear in the first column but as a result all subsequent columns have shifted to the left by the amount of characters ...
3
votes
1answer
47 views

Filter out inconsistent data blocks

I would like to filter out rows that has inconsistent geno values in line-part blocks. In case of duplicate consistent values , I would just keep the first row. As example, 'gf345 part1' has more ...
1
vote
1answer
50 views

How do i insert a character at the beginning of each line of a paragraph that contains string

Sort of different request here, but i have a text file in which i need to place a @ character at the beginning of each paragraph (paragraphs=separated by blank lines) that contains a certain search ...
1
vote
1answer
50 views

Remove and replace between two specific strings using sed command

Hi I have a SQL file i wanted to remove case statements which are present in a single line as well as case statements which are present in multiple lines. For example, my input file is: Select a, b, ...
1
vote
1answer
57 views

delete non important characters from command output

the version command in my Linux machines display the following output version Red.Hat.OS. release..........5.5 APP.Release.............4.2.0.0-02 how to remove the middle "." dot character ...
1
vote
1answer
133 views

substitute complex text string in several files that contains special characters

I need to replace a complex string in several files in a directory. The string that needs replaced is: ...
1
vote
1answer
55 views

Create files from templates, substitutions in middle of other words

Is there a way to convince m4 to replace a macro in the middle of a word? I would like this file, day.m4: define(Sat,Cat)dnl Saturday and this command: m4 day.m4 to produce this output: ...
1
vote
1answer
357 views

How do I use the SED command to remove injected code from multiple files?

One of the domains on my Centos 6.5 (64 bit) server has been compromised. Having run a detection script on the public_html folder I have identified all the files with this code injection. I ...
1
vote
1answer
228 views

Insert a line after a block of text with sed

I have text file: file.conf ### Option: LogFile # Name of log file. # If not set, syslog is used. # # Mandatory: no # Default: # LogFile= ### Option: LogFileSize # Maximum size of ...
0
votes
1answer
31 views

Big XML - copy data from nth Occurrences to another file

<XML> <Employee> <firstname></firstname><lastname></lastname> </Employee> <Employee> ...
0
votes
1answer
27 views

Script to remove certain span elements from an HTML file

I want to write a script that completely removes every instance of a particular span class from a given HTML file. For example, if my undesired span class is "foo" then running my script on the file ...
0
votes
1answer
47 views

Replace command in Bash script from another script

I'm trying to setup a script that will fetch changes from github where a script has a command that's not executable in Mac OS X. What I'm aiming for is to use sed etc to replace the command within ...
0
votes
1answer
45 views

Find part of String and replace entire string in a file

I have a file named A.xml which contains a strings such as "Ticket_Release1" and "Ticket_V2". I want to find and replace all the strings in the file starting with Ticket_ with something called ...
0
votes
1answer
78 views

sed: extra characters after command

i have a text file and i want to remove all lines in it that have EXPRESSION_1 in them. I type sed 'd|EXPRESSION_1|' filename.txt > tempfile.txt and get the output: sed: -e expression #1, char ...
0
votes
1answer
83 views

load bash comands from file one per line and execute them for each file in a directory

I'm trying to write a bash queue which will be able to load command set from a file and then execute each over set of files. prepared file should serve as a template for execution in manual bash ...
0
votes
1answer
72 views

Delete customers domain extension only (in .csv file)

I have a list of my customers emails and want to remove some that end in .br for example. I would normally do the following command: sed -i '/.br/d' customers.csv But that would also delete a ...
0
votes
1answer
94 views

Cutting logs (and not copying) from a log file between two time stamps

I have a very huge access.log file of 2 Gb containing apache access logs. The date time format in that is as below : 04/May/2015:02:15:25 I want to cut (and not just copy) the logs from this ...
0
votes
1answer
68 views

Use sed to only replace namespace in an element that has a parent element with a given attribute value

I want to replace the namespace in an xml file using sed (I've given up trying to do it from ant, where it is required). The main issue is that that there is a repeating list of elements - not all of ...
0
votes
1answer
50 views

replacing multi line string with another multi line string using sed

for eg. input : // copyright package com.base import com.base import com.base ... i want to replace the pattern "// copyright\n\n^package.*" with another string i'm trying to do using sed -e ...
0
votes
1answer
45 views

Sed a plist file gives a iilegal byte sequence

With a Unix Mac 10.9.5, French CA version I've read a lot of tips but if the error is gone, the plist is corrupted. the locale command gives: LANG="fr_CA" LC_COLLATE="fr_CA" LC_CTYPE="fr_CA.UTF-8" ...
0
votes
1answer
31 views

Multi line substitution duplicating across lines in OSX

I'm a little rusty in my sed and haven't used it much since moving to a Mac but I am aware there seems to be a difference with what sed is used on a Mac per Ubuntu after a few searches. What I am ...
0
votes
1answer
77 views

Space removal after a pattern in SED

I have a file instrument.xml bash-4.1$ more instrument.xml <instr instr_id="CPT-2380950-011-001-826" valor_ch="" instr_type="CurrentAccount" instr_name="CPT-2380950-011-001-826" qn_type="1" ...
0
votes
1answer
138 views

Reading a string till a key word and replacing from there with another string

I am new to UNIX and am practising shell scripting. I have an application where I need string searching and replacement. There are some lines in a file 1 and file 2. I have a search key word. If the ...
0
votes
1answer
153 views

Sed with angle brackets

This works sed 's/[[:space:]]*<default>false/XXX/' Why does prepending a > make it fail sed 's/>[[:space:]]*<default>false/XXX/' escaping the > does not help either. In ...
0
votes
1answer
95 views

Need to swap the -(minus) sign for only numbers and not text for a given row

I have a input in which delimeter is <;| like given below:- 1-<;|3-Text <;|3.13-<;|0.28-<;|9 0.12-<;|2-Text <;|3.99-<;|4.11-<;|6 0.13-<;|3-Text ...
0
votes
1answer
83 views

Replacing code between two JavaScript comments

I need to set a value of JavaScript variable from bash. Variable lives in index.html file and I'd like to use unix SED command to do that. Inside index.html I have it lake this: <script> ...
0
votes
1answer
85 views

Remove given parts of a string with sed?

$ echo '<a href="mailto:NA?Subject=AB42525216 - FOOBAR bla bla - bla">NA</a>' <a href="mailto:NA?Subject=AB42525216 - FOOBAR bla bla - bla">NA</a> $ echo '<a ...
0
votes
1answer
38 views

sed replace misplaces slashes

I have the following code in a LaTeX file: for \emph{service} in \emph{host}.resources: for \emph{file} in \emph{host}.resources: \underline{service}.requires.add(\underline{file}) ...
0
votes
1answer
262 views

Search for pattern across multiple files and replace a sub-part in all occurences

I am helping a friend with her thesis written in LaTeX and I need a quick solution for a "search and replace". Using a terminal in Linux, how can I find the following pattern: \caption{*\cite{*}} ...
-1
votes
1answer
50 views

Using Sed or awk to put a string at the end of a line

I am trying to place a different sting at the end of each line using. The below works but not when the file is large. x=line # in the file. The data goes to the end with $. Let data=0 Let x=0 while ...
-1
votes
1answer
98 views

How do I change the Old Directory path to New Directory path using SED command

I have the old path it contains the some files. /home/ubuntu/Desktop/test-dir Now I want to change the test-dir to new-test-dir directory. /home/ubuntu/Desktop/new-test-dir How do I change ...
-2
votes
1answer
61 views

Extract/print every 3rd occurence of pattern

I need help with extracting/printing lines until a stop pattern. This needs to happen after every 3rd occurrence of start pattern, i.e ERROR_FILE_NOT_FOUND and continue until the end of the file. ...
2
votes
0answers
128 views

Bash - Convert escape character colored text to BBCode

I want to convert a terminal escape-character colored text file to BBCode colored text. For this i've created an Android logfile with logcat -Cd > /sdcard/logcat.txt. The -C switch adds the color ...
2
votes
0answers
2k views

sed couldn't flush stdout no space left on device?

What could be the reason for this error : sed couldn't flush stdout no space left on device This is come of the stuff that i am doing at last in my code sed -n '/.*needs to be executed ...
1
vote
0answers
44 views

Using sed to unlock fields in a pdf

At my job we regularly unlock the fields of pdf files in order to edit them using this sed script in a .bat file: type %1 | sed -E 's/(.*\/T\([a-zA-Z0-9]*\).*)\/Ff 1(\/?.*)/\1\/Ff 0\2/' | sed ...
1
vote
0answers
91 views

Sed regex printing into a file.txt

I'm connected to a MQTT stream, and I filter out the data by entering : mosquitto_sub -d -t +/# 2>&1 | sed -n "/PUBLISH/{s|.*\('.*',\).*|\1$(date),|;N;s/\n//;p}" into the Ubuntu terminal. ...
1
vote
0answers
82 views

sed stdin behaviour

Using sed for a direct stdin treatment of data, I expect that a line is treated after the enter. This is what happens when I test on CygWin or Linux but on my AIX, a second new line is needed to treat ...
1
vote
0answers
125 views

OpenWRT missing OD (octal dump)

I have a bash function using od command. Now I'm trying to run in on OpenWRT and see that in has not od. Also can't find it using install from opkg, because I can't find it. Is there a possibility to ...
1
vote
0answers
100 views

Why doesn't this sed substitution for a non-ASCII byte work?

I tried this substitution with GNU sed on OS X (4.2.2 installed through Homebrew). But it doesn't work. printf "Hello\x92 World" | gsed -r "s/[\x92]/'/g" The expected output is: Hello' World The ...
0
votes
0answers
21 views

Sort Checkpoint Firewall log into easier output

I am trying to sort out this log: Aug 27 01:23:38 1.1.1.1/1.1.1.1/1.1.1.1 fw1-loggrabber[0000]: loc=12569|time=2015-08-27 ...
0
votes
0answers
37 views

Searching and replacing string using sed

Searching and replacing a string in a file. Input file name - Input.txt Following is the content: DATETIMEOFFSET(20) datetimeoffset(99) DatetimeOffset(10) lots of data1 lots of data2 ...
0
votes
0answers
106 views

tmux status bar path customization with sed

On the server I connnect to my home path is like this:/home/junk1/junk2/user. I can use the sed command pwd | sed -e 's|^/\([[:alnum:]]*\)/[[:alpha:]]*/[[:alpha:]]*|/\1|' to shorten the directory path ...
0
votes
0answers
88 views

SED: print entire paragraph for specific pattern while loop

I find partial answer about my problem on this question but i still have trouble. I need to use a variable as a pattern for the sed command in a loop sed -e '/./{H;$!d;}' -e 'x;/'$var'/!d;' The ...
0
votes
0answers
46 views

SED and regex expressions… addr1 and addr2

How can I use sed to match 'addr1' and reuse it again in 'addr2' field? #Ex.: echo "12a34" | sed 's/a/#bcd/g' # 12abcd34 #\# = match addr1
0
votes
0answers
35 views

to check fields in configuration file

i have configuration file in which first field is filename, second field is the column if we find the value of that column is null in the filename that is given in first column. if any of value of ...
0
votes
0answers
122 views

Find & replace image URLs in one file from another file

I am trying to replace all the image source URLs in an HTML file from a list of URLs in a text file. File1.html <td class="MetadataRes" width="380px" colspan="2" style="border-top: 1px #336699 ...
0
votes
0answers
686 views

Dynamic search and replace in Ksh

Machines at work follow a constant naming pattern: host[domain]_[id] where [domain] is either "d" for dev machines and "p" for production machines, and [id] is a 2-digit string that is different for ...