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

learn more… | top users | synonyms

0
votes
1answer
5 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
3answers
28 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>
1
vote
2answers
26 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 ...
2
votes
1answer
3k views

How can I use sed to modify a line of a configuration file?

My configuration file has the following format [general] setting1=true setting2=value2 [ssl] setting1=sadfsdf setting2=sdfadsfkljasdf How would I change setting 1's value to false? If I could just ...
1
vote
1answer
21 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
3answers
176 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 ...
2
votes
3answers
28 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
32 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
vote
3answers
37 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 ...
-1
votes
1answer
31 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
3answers
43 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
2answers
24 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: ...
-2
votes
2answers
57 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 ...
3
votes
4answers
3k views

sed: delete all but the last X lines of a file

It can be done with other tools, but I am interested to know how can I delete all but the last X lines of the file with sed.
0
votes
2answers
471 views

Bash script: Use variable in sed to delete all but the last “x” lines of a file

I'm using the following bash script to delete all but the last 'x' lines in a log file: #!/bin/bash # Script to write to the log file every minute and delete all but the last # set time in hours ...
0
votes
0answers
15 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
36 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
44 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
22 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
1answer
30 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 ...
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
17 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
18 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 ...
3
votes
5answers
410 views

Extract lines based on long list of line numbers

I have a long list of line numbers (35389208) that I do not want in my file. By line number I mean the line in my file (e.g. line 277). My list of line numbers I do not want looks like: 277 278 279 ...
0
votes
1answer
138 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 ...
0
votes
2answers
53 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
28 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 ...
21
votes
6answers
13k views

How to mass prepend text to file names?

Lets say I have a directory full of .md files all named various things. Lets say I wanted to prepend "text" to the front of each file name. So for example: file a.md, b.md, and c.md would become test -...
15
votes
7answers
8k views

sed: how to replace line if found or append to end of file if not found?

With a single input file that only contains comments (starting with #) and VARIABLE=value lines, is it possible to replace a value for a single variable if found and, otherwise, append the pair to the ...
27
votes
6answers
8k views

Substitution in text file **without** regular expressions

I need to substitute some text inside a text file with a replacement. Usually I would do something like sed -i 's/text/replacement/g' path/to/the/file The problem is that both text and replacement ...
1
vote
2answers
208 views

Zsh autocomplete function with sed

I'm struggling to write an ZSH autocomplete function. My goal is to autocomplete ta's and tk's first argument with the projects listed in tmux list-sessions and tmuxinator list. Here's what I have so ...
3
votes
5answers
4k views

How to remove lines from large text file using bash

I got a huge text file (log file) in my CentOS which I would like to remove top part of, probably couple of thousand lines each day. (Or probably just split into two) I have search this site and ...
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 ...
3
votes
3answers
2k views

How to remove comments in all files including in subdirectories?

to remove comments (start with # and /* comment */) in settings.php, below command is just works fine: sed '/^\#/d' settings.php > outp.txt mv outp.txt settings.php sed '/\/\*/,/*\//d; /^\/\//d; /^...
28
votes
12answers
19k views

Efficiently remove the last two lines of an extremely large text file

I have a very large file (~400 GB), and I need to remove the last 2 lines from it. I tried to use sed, but it ran for hours before I gave up. Is there a quick way of doing this, or am I stuck with ...
5
votes
2answers
4k views

Finding and deleting lines from all files recursively

I have managed to grep the occurences of a keyword by using grep "KeyWord" . -r -n -i -I but, the occurences of the KeyWord are too large. I just want to delete all the lines containing that word. ...
-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 ...
5
votes
3answers
12k views

How append a string at the end of all lines?

I'm trying to add a string at the end of all lines in a text file, but I have a mistake somewhere. Example: I've this in a text file: begin--fr.a2dfp.net begin--m.fr.a2dfp.net begin--mfr.a2dfp.net ...
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/...
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): ...
1
vote
1answer
28 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....
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 ...
1
vote
1answer
39 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?
0
votes
3answers
351 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
2answers
385 views

How to replace a line in an xml file with a set of lines stored in a variable or file using unix commands?

I have a xml file in which the line that needs to be searched is: SEARCH='<?xml version="1.0" encoding="UTF-8" standalone="no"?><SSC>' This searched value needs to be replaced with ...
-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.