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

learn more… | top users | synonyms

0
votes
2answers
14 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
25 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
24 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
21 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
39 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
28 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
22 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
20 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
26 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
34 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
28 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
48 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
49 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
35 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
24 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> ... ...
0
votes
4answers
90 views

How do I DELETE a comma and a space from a numeric string using a bash script

Folks, I have asked this question 5 times on here and have received 5 separate bits of code from super users that have all *failed. Problem: I have stock information being brought back into a txt ...
1
vote
1answer
54 views

Using cURL command-line tool on Mac, What can I do to this script to ask it to fetch stock data which will replace commas with NO SPACES

Example: Google Outstanding Shares are 670,000,000 and this value is collected in a txt file from Yahoo Finance API via the below script. The issue is; that numbers WITH commas or spaces are a bloody ...
2
votes
1answer
15 views

Use argument of unrun command in Linux

If I wanted to run mv arg1 $(sed arg1 's/regex/replace/') is there a better way to to do it than to reinsert the filename into the sed command?
0
votes
1answer
20 views

have sed translate both cases from lowercase input

I have variables from="abc" and to="xyz" defining lowercase strings. How can I use sed so that it replaces from by to, but matching the case. That is echo "abc def ABC DEF" | <sedcommand> ...
0
votes
1answer
62 views

Sed replace line stored in a variable

I need to find a line that starts with mysql.unmetric.twt.url and replace the entire line with line stored in the variable ip. ...
0
votes
1answer
25 views

Sed and Replace

I need to find a line that starts with mysql.unmetric.twt.url and replace the entire line with line stored in the variable ip ...
0
votes
1answer
20 views

How to fetch the string “Hi there” from the below array in unix

I only want to fetch Hi there and store it in a variable VAR1. So basically VAR1 should contain Hi there VIEW_COL[1]="Hi there,USA,Y" This is what i have tried so far. Column_Display_Name=`echo ...
0
votes
1answer
44 views

I want to append the name of the file on the top of that file using bash script

I want to add void mainfunction() on the top of a file. I am reading the actual name of the file from another file and the name of the main function from another file. I was using: sed -i 1i void ...
0
votes
3answers
22 views

Filtering 2nd field from a data set and then using uniq on the output

I've got a dataset that goes like this: AAAAA 11111 Data1 AAAAA 11111 Data2 AAAAA 11111 Data3 AAAAA 11112 Data4 AAAAA 11112 Data5 AAAAA 11112 Data6 AAAAA 11112 Data7 AAAAA 11113 Data8 AAAAA 11114 ...
0
votes
2answers
40 views

Text deletion between patterns across multiple lines with respect to text inside pattern

I have a block of text I need to delete, however, only if it contains specific text inside the block: ... <script language="JavaScript"> var somethingA = 0; var somethingB = 0; var ...
1
vote
3answers
49 views

Two very similar lines of sed, can they be combined?

I have the following two lines in a shell script and was wondering if there was any way to condense them into one using sed. I am not sure if there is a wildcard or anything that could replace the ...
1
vote
1answer
49 views

bash script processing files with bad characters

I received a zip file with a folder structure that include parenthesis. I've worked through two processes at the cli and now merge them into a script The first searches through the file structure for ...
1
vote
2answers
48 views

Replacing several strings in a file in one go

Suppose I want to replace all AAA with BBB and all BBB with AAA in a text file. The thing which looks an obvious solution (in Perl or in Sed) is: s/AAA/BBB/g; s/BBB/AAA/g; But this does not ...
0
votes
1answer
54 views

mod_sed - apache+sed - problems with backslash

I have just started using sed and are having a problem when using sed from Apache mod_seq. The task is to change a web service post to a file upload post. Content-Type has already been changed using ...
1
vote
1answer
36 views

How to Extract Multiple substrings from Log FIle

I am trying to extract the timestamp and the number string in the URL called in an apache logfile that looks like this: 123.456.78.90 - - [16/Dec/2014:06:27:30 +0100] "GET ...
0
votes
1answer
40 views

What does `-n` option in sed do?

This is the man page entry for -n: -n suppress automatic printing of pattern space I notice that when not using -n for certain operations, each line is printed to stdout (and the requested ...
4
votes
1answer
64 views

Can I create a “file” that, when opened, actually gives the output of a command?

I've found myself in a couple of situations now where I'd like to have such a "file" that essentially runs a script whenever it's "opened", allowing me to "read" it's output. For example, I might ...
1
vote
1answer
40 views

How to delete the 3rd occurrence of a pattern in a file, and beyond

How can I find the third occurrence of a pattern in a file (Note: not in a line) and delete the line containing the pattern and n lines below that (say, 5 lines below). e.g., COVER fafjasfj isfapifj ...
2
votes
2answers
202 views

Sed replace between 2 strings with special character

I have an XML file containing a code and to use it with xmllink I need to remove a link. XML file containing: <xml version="1.0" encoding="UTF-8" standalone="yes"?> <PackingList xmlns="Link ...
0
votes
2answers
58 views

Replace random string using sed

How do I replace random strings using sed. For example if I have a text file like this: EF125353.1 to be replaced 1 EF125353.1 to be replaced again 2 EF125353.1 to be replaced etc etc 3 ...
1
vote
2answers
93 views

use sed to replace a specific string with slashes

I have a big text file -a windows registry file- about 5.5MB and I have to remove a string "serv\b\Param\". Opening with gedit or nano doesn't work. It will either consume 100% cpu time for some ...
0
votes
0answers
17 views

Why does sed accept \s (only when not in a character group)?

Okay, so I have always used \s to match whitespace but now I have been having a bit of difficulty as with sed, while trying to do a negated character group match [^\s] I found this does not work. ...
1
vote
1answer
70 views

Using grep, sed or awk to find words in between? I want to be able to extract the package name until .el7

I am writing a script (bash/command-line) and I want to be able to extract the package name until .el7 x=dbus-sharp (an example package name - which changes) example text file: Building ...
0
votes
1answer
71 views

GnuWin32 / sed unexpected behavior in Powershell

I am using GnuWin32 tools on Windows Command Line/Powershell. What is see: 11:15 enlil D:\Users\x> Get-ChildItem .gitconfig | sed "s/ */ /g" D i r e c t o r y : D : \ U s e r s \ x M o d ...
0
votes
2answers
24 views

how to retrive value between double quotes with multiple double quotes in line using sed

I am trying to use sed to retrieve value of 'identifier' from below line which is string 'TestStudioJobResponseMessages' in below example, also I don't want to use string uuid in my sed expression as ...
0
votes
1answer
103 views

Awk script to run a command based on condition using 'if'

I have a piece of code here that basically takes a file called 'srcip' (which is just a list of IP addresses) and compares it to my '~/db' file which is just a tab delimited IP HOSTNAME database of ...
0
votes
1answer
42 views

is there a way i can either insert a character into a line or substitute and arbitrary character with itself plus some other carachter(s) in sed?

like say i have a string of numbers that constitute a phone number and are like so ########## and i want to format them like : ###-###-#### insert only puts in new lines, and i dont know how to ...
0
votes
1answer
23 views

How do I search for and delete just the endings of list of directories using 'sed' command?

How do I use sed to delete just the '-bak' portion of the following list of directory names: accesscode-bak adminconsole-bak adoptimizer-bak ads-bak ahcms2-bak alerts-bak alfresco-bak
1
vote
2answers
82 views

Grep output from multiple lines in a limited shell environment

I have been scouring the web for ways to search across multiple lines of output and then print the lines which contain the strings I care about. I am actually running this on a checkpoint firewall, ...
-2
votes
2answers
44 views

How can I use a “<” character in sed?

I am trying to replace this line with a <?php tag with sed using the command: find . -name "*.php" -type f -exec sed -i '/if(!isset($GLOBALS/<?php/d' {} \; When I run the script, it generates ...
1
vote
2answers
39 views

how to see contents of a file (cat file) but eliminate a certain string in many lines

I have a file like this: ins.pro.server.pro.net ins.pro-server2.pro.net ins.pro-server3.pro.net ins.pro-server4.pro.net I would like to cat this file but eliminating the specific string ".pro.net" ...
1
vote
1answer
160 views

Bash/Sed how to insert a string with special characters into a file

I have a script that I'm currently working on. And I've run into an issue where I need to prompt a user to enter a string, then encrypt that with sha-512, and then insert it into a specific file So ...
2
votes
2answers
56 views

Replace Line Breaks on matching lines, using AWK

I have the following data What i'd like to do is for every line, where there is no ,"555" at the end, I want to remove the the line break, \n, and replace it with space. So, the 'matching line' ...
0
votes
0answers
103 views

how to show battery percentage on gnu screen hardstatus line

I currently have this as my hardstatus last line on gnu-screen the ~/.screenrc entry is as follows (just incase someone want something similar) hardstatus alwayslastline '%{= g}[ %{G}%H %{g}][%= ...
1
vote
1answer
37 views

Get a range of lines from a file and replace a line in that range using awk or sed or both

I would like to replace a line in a section of the smb.conf file using either awk or sed or both if need be. Here's the section in the file... [CMI] oplocks = no wide links = no writeable ...