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

learn more… | top users | synonyms

0
votes
2answers
25 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
22 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
0answers
12 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
16 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
18 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
19 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
540 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
25 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
39 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
54 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
10 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
37 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
70 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
25 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
45 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
17 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
35 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
21 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
76 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
37 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
0answers
76 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
44 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
28 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
29 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
79 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
40 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
78 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
61 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
40 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
16 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
47 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
74 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 ...
-1
votes
1answer
31 views

How to show a particular section from a line in linux?

Let's say I have a file with the following line: ...
3
votes
2answers
30 views

How to get command output of “nvidia-settings” via command line?

the case at hand: nvidia-settings -q all | grep 'Attribute.*GPUCoreTemp' gives: Attribute 'GPUCoreTemp' (system5:0.0) 58. Attribute 'GPUCoreTemp' (system5:0[gpu:0]): ...
0
votes
4answers
103 views

How to replace first n no. of occurrence of a string using sed and/or awk?

I got a file alphabet where a has multiple occurrence in a line. $ cat alphabet a b c d e f g h i j k a a l m n a p q r a s t u v w a x y z a k l q z where $ cat alphabet | grep -o a | wc -l 7 ...
0
votes
1answer
80 views

How to run regex find and replace using windows command line

I want to perform complex find and replace that I do with notepad++ using command line. I found many solutions from web but none of them matches my requirements. I have one file in which I want to ...
0
votes
1answer
58 views

Sed (or other) script to replace a character within the capture group

I'm attempting to convert Pandoc markup to Confluence wiki markup, I'm using markdown2confluence to do the bulk of the work. This works quite well except where I'm talking about CSS and FreeMarker ...
0
votes
1answer
66 views

mv in for loop : “when moving multiple files last argument must be a directory”

I try to rename few files, omitting the first n characters. In fact I want to remove the [ www.blabla.com ] prefix (18 chars). I'm on windows, using bash command on Git-bash. I've tried this ...
2
votes
1answer
48 views

Special equal character with sed from shell

My environment: I am working with the command interpreter on Windows. I use an sh.exe that came with some proprietary tools I have installed. I do not know the details of that sh.exe but here is ...
0
votes
2answers
40 views

Multi Find and Replace Html Code

I have a URL error across multiple html files that I need to find and replace. Currently my pages show: src="//https: and I need to find and replace all with: src="https: Does anyone know a way ...