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

learn more… | top users | synonyms

0
votes
2answers
29 views

sed command to replace multi-line text with empty

I have an XML file which contain portion as given below. <Target name=something> < other content here> </Target> Now how can I remove this content from my file using sed ...
0
votes
0answers
18 views

sed command removes parent closing tag in xml file

Iam using sed command to replace a string with another in an xml file using below given the command. sed "s/one/two/g" /data/common/codeset-mapper.xml > /data/codeset-mapper.xml But the closing ...
0
votes
2answers
28 views

Combine multiple lines in a file to a single line

I have a file as below.. "Field1"|"Field2"|"Field3"|"ufghjkrtyrtyfgh$" "Field1"|"Field2 continue on line 2 continue on line 3"|"Field3"|"ufghjkrtyrtyfgh$" ...
0
votes
1answer
15 views

Removing “<<” and “>>” from a file using a sed script

I have a text file which has a few "<<" and ">>" which I'd like to remove. I tried the following: sed -e 's/>>//' -e 's/<<//' -i .ORIG file but it does not work. (I also tried ...
-1
votes
0answers
16 views

Self-contained installer in korn shell script with sed, grep and gzip

There's a great post on this here: http://www.matteomattei.com/create-self-contained-installer-in-bash-that-extracts-archives-and-perform-actitions/ But is uses Bash interpreter, tar and awk. I need ...
0
votes
1answer
14 views

Using sed to move part of filename

I have some music files which are named as 'track name [artist]'. I want them to be '[artist] trackname', and so need to move the square brackets and what's in them to the start of the file. I've ...
0
votes
2answers
15 views

List only interface names for ifaces that have 'parent: eth0' field in ifconfig output with sed and/or grep

ifconfig output: lo: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33192 inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid ...
0
votes
2answers
88 views

Windows 10 does not recognize hardware encrypted bitlocker volume

I use Windows 10 Pro/Education on a self encrypting Samsung SSD Drive (Evo 850) and configured/installed it by following this guide [1]. I configured bitlocker to ask for a PIN before booting Windows ...
0
votes
2answers
41 views

From logs, extract specific line after a grep by line number

I have a file, debug.log, from which I want to extract all the lines that immediately precede a specified pattern. Example: 1 blabla 2 blabla 3 HERE THE IMPORTANT THING 4 HERE IT MATCHES MY PATTERN ...
0
votes
2answers
26 views

Extract only matching pattern in a single line of text

I have a compressed Javascript file which is in a single line form and contains bla bla bla,;xyz=require("something"),blablabla=3xyz; if (require("somethingElse") === bla bla I want to extract the ...
0
votes
1answer
23 views

Combine 2 xml tags with SED

I create an xmltv.xml for TV listings and need to use SED for some post processing. Im using Windows 10 with SED for Windows run via a bat file. The trouble is only certain tags are shown on my ...
-1
votes
1answer
17 views

How can I filter unique lines based on a substring?

If I have a set of URLs in a file like: http://example.com/do?foo=bar&etc=123 http://example.com/do?etc=456&foo=bar I want to filter this out so that there's only one url for each unique ...
0
votes
1answer
32 views

How do I change a few letters in a large text file

I have a large file file.dat, a database dump in a CSV format that looks like this: file_id,line_id,st_x,st_y,value1,value2,...value100 111111,1,22.22222,33.33333,0.1234567,0.246890,0.369258,... ...
1
vote
2answers
20 views

Append filename with text from a specific textfile

need some help. I have a file called domoticz.backup.tar.gz I allso have a file called History.txt that in the first line says Version 3.4834 (March 2nd 2016) I would like to add the 3.4834 to the ...
0
votes
2answers
24 views

Insert a string or blank line after specific search criteria, in a loop

I'm wondering if someone could help me with a specific coding question. I have a DNA sequencing file that reads something like this (as an example): ...
3
votes
2answers
809 views

Using sed within a vi buffer

In a long text file listing dups-23Mar16.listing I want to delete lines beginning, for example, with .local. Here are some lines in this file: ...
1
vote
1answer
26 views

How to use the “sed” command to remove all lines that do not end up on the pattern?

How to use the "sed" command to remove all lines that do not end up on the pattern? Example (.txt - pattern) aaa aaa.com b b b b.txt ccc ccc.gif dd dd dd.txt I want to get: b b b b.txt dd dd ...
2
votes
1answer
49 views

Merge only new entries from one xml file to another

I have 2 xml files. The 2nd file has some new entries including same entries as that of the 1st file. Examples of the 2 files are given below. File 1 <SERVERNAME_ONE> ...
1
vote
2answers
41 views

Grab a section from a large file between two known substrings using sed?

I have a pretty large XML file without line-breaks. It's so big it's slow to open and operate on in Emacs or other text editor. But I just want to extract a shortish section of it between two known ...
0
votes
2answers
68 views

using sed in BASH script: replace text with info from system variables (hostname and date)

I want to use a bash script to run a backup and then send me an email using ssmtp. I am trying to make a generic script that I can reuse across different Linux machines. Below is a snippet of the ...
0
votes
1answer
15 views

Why sed regexp digit character class includes CR character if the last digit is at the end of the line?

I wanted to extract the Content-Length's size from an URL and output the URL + $size on the same line. The data I worked with: > curl -I -s http://yahoo.com HTTP/1.1 301 Redirect Date: Thu, 10 ...
0
votes
0answers
15 views

Convert list of Hardened Linux From Scratch packages into suitable format for md5sum -c

I'd like to create a file suitable for using with md5sum -c from this document: http://www.linuxfromscratch.org/hlfs/view/development/chapter03/packages.html I imagine this should be possible by ...
-2
votes
1answer
40 views

Transpose text using Sed

Please help me figure out how to solve this using sed. Given the following text: Kerala 4222 8129 8163 8164 Delhi 8502 8503 8504 ...
2
votes
3answers
73 views

How to use xargs and sed to pipe results to an array?

I'm pulling JSON from a REST endpoint using curl and then parsing it using the node package json to get at some of the JSON attributes, which I use later in some app configurations. curl -s ...
1
vote
1answer
27 views

chunking screen output using grep/head/awk/sed/etc

I have some output that prints an element every line. I want to be able to parse that output in chunks of N, even if the number of lines is not a multiple of N. find . -f | chunk 10 1 # shows first ...
0
votes
0answers
46 views

Fastest possible 1-liner request generator on Linux webserver

Long story short, I want to make the following 1-line script as fast as it can get: tail -f access_log | grep -v 'some_requests' --line-buffered | sed -u ...
0
votes
1answer
18 views

Centos 6.7 sed replace text with string + char $

for command sed, how can I replace text with string consist "$". e.g. sed 's/ABCD60/$1$20ABCD' where '$1$20ABCD' is a random string
0
votes
2answers
37 views

How to add a new line to the top of the file- OSX&GNU

i tried the below to add a new line to the top of the file but to no avail 1) seems to work but how do i do it inplace ? perl -lpe 'BEGIN{print "somestring\n"}' file 2 ) sed -i.bak -e '1i somestring ...
1
vote
1answer
24 views

Overlapping replacements with sed?

Suppose I have an input string: ,,a,b,c,,,,d,e,f,,,g Is there a simple sed command that can insert something between every pair of consecutive commas? That is, what can I use to convert the input ...
0
votes
1answer
22 views

How to Check value for an input element after fetching contents of page using cUrl

I am trying to download a page using cUrl. I have saved the page to a file and I then grep on it to extract the value of the text field. The text field appears multiple times and I just need one ...
1
vote
0answers
88 views

Self-Encrypting Drive (SED) and S3-suspend (sleep)

since my laptop is aging, but I love its 4:3 screen, I don't like relying on external media (also no USB 3 ports), and SSDs are too small for my budget, but I want full encryption (previously ...
0
votes
1answer
41 views

sed align all lines to last line in a file Bash script

I have a files with below lines Dev_Campaign_1873.rpm Dev_Campaign_1987.rpm Dev_Campaign_9876.rpm http://52.30.241.107:8081/artifactory/api/storage/adifact Trying to get the output to a file as ...
-1
votes
1answer
35 views

Oneliner to get the list of filenames which have last line (or line on position X) matching certain pattern?

How to get the list of filenames which have last line (or line on position X) matching certain pattern? We are looking for oneliner.
0
votes
2answers
31 views

Unable to add spaces

How can i add spaces between my outputs using sed/echo or any other command in linux? Preferred Output: Virtual Machine Test01 status Running. Virtual Disk Test01 size 61GB Physical Disk ...
0
votes
1answer
105 views

How secure is BitLocker without a TPM, using SED?

I'm trying to find a source for some basic information about BitLocker. Say I have a self-encrypting drive (SED) like a Samsung EVO, but no TPM. I enable BitLocker. There are two options: Password ...
3
votes
3answers
60 views

How to append to the first line of a file?

How can you use sed to replace the entire first line of a file with that first line plus some additional text? For example, how can I append -foo to a file that contains only one line. testfile ...
0
votes
0answers
30 views

Sed command to replace NUL character in file

I am using the command sed -i 's/\o000//g' filename or sed -i 's/\x0//g' filename to remove the NUL character but the command works fine in DEV environment but doesnt work in UAT. OS and sed version ...
1
vote
1answer
38 views

Remove a certain part in a text file

I got the file, text.txt. In this file I have written: "test" "okay" I want to remove the " part of this file, how'd I do this?
2
votes
1answer
32 views

sed, regex replace with vars

I'm trying to use sed (4.2.2-4+b1 debian 8 (jessie)) to replace text in multiple files. To go from this: $var1 = array(foo=>"bar",bar=>"foo"); $var2 = array( foo=>"bar", bar=>"foo" ); ...
1
vote
2answers
88 views

Using Sed Ampersand Substitution with Array

I am trying to use the ampersand character of sed to replace with the original string, and then read from the array, but it is not working. I just get the error: 'operand expected (error token is ...
0
votes
1answer
42 views

redirect ALL output from shell to a command to act as filter

How to redirect all std-output from bash to a command like 'grep' or 'sed' to filter the output and then write it to a file? This is what I want in principle: exec > >(cat | cat ...
0
votes
2answers
99 views

Rename CSV header using command line tools

Given a CSV file, h1 h2 h3 a b c z x b how to rename the first header to One and the third header to Three using command line tools, namely One h2 Three a b c z x b
0
votes
1answer
28 views

Transform CSV column by a function using command line tools

Given a csv file such as h1 h2 a 0 b 1 c 0 how to rename 0 to YES and 1 to NO in the second column.
1
vote
3answers
75 views

sed command in console works; but in shell script it throws error

I am trying to write a shell script to replace the SEARCH string by REPLACE string in all the files of the current directory (directory where my script remains). The condition I have is : the script ...
0
votes
1answer
27 views

Linux, how do I use sed to edit apostrophes?

So I need to edit a bunch of html files.. I've used sed before, in batch, but the problem I'm having is that my string of text to locate and replace both contain apostrophe's. While you can change ...
0
votes
3answers
42 views

combine xargs with sed to modify or change a a file

I'm searching the general pattern ***_23 on the end of a line ( but not: at_23) inside a file , and than I'm trying to change all those findings to \<23>, in the same source file ( insert function ...
0
votes
2answers
17 views

Ubuntu replace expression in dir and all sub directories

How can I replace an expresion that has a forward slash with another in all dirs and subdirs? I used this to find: grep -rnw "/var/www/site" -e "app/COD1" And now I want to replace: "app/COD1" with ...
0
votes
3answers
54 views

Substring in string in bash?

What is the equivalent of the python statement in bash: if "mystr" in "a long string with mystring in it": print("found string") The offset in number of characters can NOT be relied on to be ...
0
votes
1answer
27 views

A way to split a text file into arbitrary blocks based on first column?

I have a (very large) text file of the form... /folder1/fileA /folder1/fileB /folder1/fileC ... /folder999/fileA /folder999/fileB /folder999/fileC ...etc with an unknown number of entries for each ...
0
votes
2answers
86 views

sed command returning “sed: bad option in substitution expression”

For example:- I have a file named file.txt $ cat file.txt $key I have a environment variable, for eg: $key in a text file and lets say $key = 1234, so I can replace the value with the below ...