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

learn more… | top users | synonyms

1
vote
2answers
33 views

grep a file and pipe the output to sed and store sed output in a file

Contents of source.txt: gold green white black blue yellow magenta brown tram kilo charlie tango Hi everyone! I need to solve a mystery. I'm trying to run a small script to grep a file source....
-1
votes
0answers
27 views

Using sed to replace string with special characters in XML file - part 2

To continue the discussion about sed, variable strings and special characters, this works perfectly : sed -i "s~${LINE}~${NEWARGS}~" $FILES for the variable with contents of: JAVA_OPTS="$JAVA_OPTS -...
0
votes
1answer
20 views

need help grep playlist

I use a playlist from the Internet that gets updated every day. I want to sort and grep URLs. The playlist is a mess and looks like this #EXTINF:-1 tvg-id="ORF1.at" group-title="Deutsch" tvg-logo=...
0
votes
2answers
40 views

How to collect specific information in a file

I have the need for different hardware information. such as serial numbers, capabilities, among many others, and for that, I found the hwinfo, but it gets information far beyond what I need. For ...
1
vote
1answer
26 views

how do I ignore special characters in sed

I have the following code; ToString="java.extended.properties=-XX:MaxPermSize\=128m -XX:CompileCommand=exclude,com/tibco/repo/RVRepoProcessBridge,handleServerHeartbeat" sed -i "s@.java.extended....
0
votes
2answers
21 views

Bash Sed Pipe to Command One-Liner

I'm trying to dump output from all of my interfaces. This is what I've got so far: ifconfig | awk '{print $1}' | sed s'/.$//' I'd like to have something like : ifconfig | awk '{print $1}' | sed s'/...
1
vote
1answer
23 views

Camel-casing a 'dashed' string

I'm fairly inexperienced with *nix scripting, and I have a need to take a string with lowercase words separated by dashes and convert that to a new string with the dashes removed, and the first letter ...
0
votes
2answers
48 views

Can I delete only the first matching line using sed?

I have a file testfile.txt containing pippo=x pluto=y 1234=z I'd like to delete only the first line matching /^[a-z]\+=/ (the first line in this example). I've tried with the following command but ...
1
vote
3answers
31 views

Using a shell script to add a ‘</pre>’ after the last line in a large file

I need a SED, or AWK, command to find the last line in a file, and add </pre> to it. Such as: LINELINELINE Changes to: LINELINELINE</pre>
2
votes
3answers
29 views

Removing characters at end of lines using find and sed

For a codebase converted from java to scala there are many files with unnecessary semicolons at the end. Here is my attempt to remove them: for f in $(find . -name \*.scala); do echo $f; gsed -i $f -...
1
vote
1answer
43 views

Linux Shell script to change grep for a string, then comment out 2 lines above and 1 below the string found in the file

Looking for some help on this task. I have tried several shell scripts to do this, but not sure I am approaching this problem right. I have a file that contains several blocks of data like this: ...
-1
votes
1answer
34 views

How can I write this sed script?

Reads input number "n" and writes 0 1 ... n to the output by "n" times, separate by spaces. For example: n=3 1 2 3 1 2 3 1 2 3 Thank you very much!
-2
votes
1answer
15 views

Removing a substring between track number and title

I need help with a little bit of bash trickery. In organizing my music collection I've come across a set of tracks which are named in the format %track%. %artist% - %title%.%extension% How can I ...
0
votes
2answers
29 views

Redirect output of 'for' loop in cygwin

I have a directory that has 3 files : a.txt b.txt c.txt I have to delete first 4 lines from each file I want to use 'sed' or 'awk' or etc in Cygwin I do this: for x in `ls`; do sed '1,4d' $x done ...
0
votes
2answers
15 views

Find highest numbered files in directory

Scenario: A backup system creates rar archives and splits them in 100 MB parts. I would like to find the highest numbered files within this directory. For example in- and output: Input: ...
-1
votes
2answers
62 views

Sed insert, copy and change, append a line of matching string

Tool: sed Requirement: I want sed to find a line with matching string . Copy the line and comment one line . Modify the other line . Insert a string above the two lines. Example: File ...
1
vote
3answers
39 views

Display file contents if it has corresponding line number

I have two files in the following format: File A 4 5 8 9 File B 1 text 2 text1 3 text2 4 text3 5 text4 6 text5 7 text6 8 text7 9 text8 What I want to have for my output is just the following (the ...
0
votes
0answers
22 views

Using BASH to create new elements in XML file

So far I have done simple things in bash with sed, awk, while loops, etc. What I need to do next is far more complicated and I'm not sure how to get started. I have an XML file and I need to add ...
1
vote
1answer
39 views

xargs with two command - mkdir and sed

I want to create catalogs and in the same line I want to change path and save it in the output file I don't want to repeat code, so I tried: cut -d ';' -f 1 tmp1 | tr '.' '/' | xargs -I % bash -c '...
0
votes
2answers
46 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
23 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
3answers
46 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$" "Field1"|"Field2"|"Field3"|"...
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 ...
0
votes
1answer
18 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
19 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
3answers
251 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
56 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
30 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
31 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
21 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
28 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
1k 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: Desktop/Reisen/Italien/VillaLaBandita/images-hpz-urlaub/...
1
vote
1answer
29 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 dd....
2
votes
1answer
57 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> <Protocol>...
1
vote
2answers
44 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
123 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
16 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
42 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
80 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 http://52....
1
vote
1answer
30 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
47 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 's/^.*(http:\/\/example.com\/blah)\/this.*$/\...
0
votes
1answer
33 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
38 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
25 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
23 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 value....
1
vote
0answers
149 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
55 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 ...