Questions tagged [sed]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
24 views

Symlinking with (i.e.) find | sed | xargs without xargs: argument line too long

I got stuck at symlinking using find, xargs and sed. Given folder structure: /abc /def /*/def /builds on my local machine the following statement works. find ./abc \ -type d \ -...
0
votes
0answers
22 views

Sed: Perform pattern search in reverse order in a certain range and get the line number on each match

I want to search the pattern in a certain range but in reverse order. For example if I give the range say 200,250 then I want that search should be performed in reverse order means search should start ...
1
vote
1answer
29 views

How to exit `sed` after the first match?

I need to search a pattern I/f in a file between some range of lines and quit on the first match. For that I am using sed command like this sed -n '14922,28875{\|I/f|=}' file.txt It actually prints ...
0
votes
0answers
12 views

Self-encryption drives authentication key via Raid controller

Currently, SED keys need to be passed to the drives via Raid controller. We are using that because we don't want someone to go on site physically and enter the password manually everytime we want to ...
1
vote
2answers
44 views

Insert output of curl command to a line number in a file

Working on a script to automate a few things. Been having and issue with running a sed command to inser the output of curl to a line number in a file I have tried multiple variations of the command ...
2
votes
1answer
37 views

regex - replace ordered list of lines matching a string with another list

I have such confused ideas I couldn't describe well the problem synthetically, hence the title is horrible. Suggest me a better one too, while you're at it. Basically, I have two SubRip (.srt) ...
0
votes
1answer
20 views

Trying to use Sed with regex to fetch data from a log file

Hello I am experience difficulty to extract data from log file with sed -E command.I see regex is different than this I use in python. INFO [2020-05-10 17:37:34] [armada.gloge] Username [109/15654] ...
0
votes
0answers
12 views

sed and android name with spaces

I gotta run a shell command grep -wlr "12.0sp" /storage/emulated/0/ApkEditor/"Phone and Messaging Storage"/w_src | xargs sed -i -d 's/12.0sp/15.0sp/g' but the sed part of the command is not working ...
2
votes
1answer
28 views

Pipe the output of “ls -G1” to “sed” while retaining output colors in macOS

When using the terminal in macOS I created an alias in ~/.bash_profile that lets me list folders and files in one column and with color using the -G1 option like this: something = "ls -G1" This work ...
0
votes
2answers
19 views

Replacing a number ended in dot at the beginning of the line with '.IP number\n'

I want to replace numbers followed by period at the beginning of the line: 1. The quick brown fox jumps over the lazy dog 12. The slow grey cat jumps over the lazy dog 234. The strong yellow lion ...
2
votes
1answer
14 views

Sed a file to include `pwd`

I'm not able to figure this one out. In a file called docker-compose.yaml I want to substitute ROSPERSISTENT-PATH with the result of pwd + "/rospersistent" which seems like a job for sed. But I am ...
0
votes
2answers
56 views

Replacing a string inside of multiple text files

I am looking for a way to replace line 5 and line 7 in many documents inside of a directory. Line 5's offset and line 7's value are different for each of these documents, however, I need them to ...
0
votes
0answers
13 views

Use sed command to replace a tag with special characters

URIS='[ "https://%something%/xyz" ]' sed -i "s|REDIRECT_URIS|${URIS}|g" temp sed does not work if I put this command in a shell script; URIs are dynamic and some of them won't have [ or ], while ...
1
vote
0answers
12 views

Modifying a PBN file with sed [closed]

(Complete beginner in sed.) In sed, how do I do the following? In the below-example .PBN (Portable Bridge Notation) file: [Deal "N:Q5.KT653.AJ.KT52 73.AQJ984.9543.8 AK9.7.Q876.AJ943 JT8642.2.KT2....
1
vote
1answer
23 views

Read a file and replace dot with colon using sed command

Im trying to read and substitute period(.) with colon (:) from the below input file using sed regex expression. Can one please check and suggest me. Input File has 12.23.45 Expected is 12:34:78 ...
0
votes
1answer
101 views

Best way to store multiple values from a running process into variables in bash

The problem Starting a process will output sensitive information on the bash. I want to extract this value of an occuring pattern and assign it to bash variables. In concrete, starting the process ...
0
votes
1answer
38 views

Removing lines from files with a specific extension

The task is as follows: From all *.h and *.cpp files, delete lines beginning with /. Removing from the current directory (or from the specified one) works well, and if there is a subdirectory in the ...
4
votes
1answer
263 views

Add a new element to existing JSON array

How can I add "arn:aws:iam::xxxxxxx:role/3" line below "arn:aws:iam::xxxxxxx:role/2" adding a comma after "arn:aws:iam::xxxxxxx:role/2",. Before: { "Version": "2012-10-17", "Statement": [ { ...
0
votes
1answer
51 views

Use a variable that could contain special characters into sed?

I have a bash script that'll take any word passed to it as a parameter and then encrypt the word using an openssl command. From there I want to take the returned string and use sed to write it into ...
0
votes
1answer
23 views

sed - replacing string with variable containing?

Please help, I am not getting anywhere despite extensive search in here. I have a html file, and I want to replace some of the links it it - problem is, some of the links have a ? in it. original='...
1
vote
2answers
69 views

how to extract a specific part of a string from character 7 to 17 and save it in new txt file (findstr, gnu32-sed or other tool)

How do I extract a specific part of a string from character 7 - 17 using regex via the command line? My string is ThisString and in the file data I have a lot of strings, but I need only ThisString ...
0
votes
1answer
57 views

How to substitute every opening curly brace that changes bracket balance from 0 to 1 with sed/awk?

Example input: void C::foo() { // <- this changes bracket balance from 0 to 1 if (true) { // balance is 2 after we process this bracket ... } // now it is 1 again } // now ...
1
vote
1answer
88 views

change line starting with# with sed -i

I want to uncomment a line in /etc/apt/sources.list to enable canonical repo but it seems it has a problem with # character I tried -e but I can't figure out if I'm doing it correctly sed -i ' s/# ...
0
votes
1answer
46 views

How to edit a multiline pattern in bash (sed and awk are available)

So here is my very specific task. I have patterns of type .*[class|namespace|struct].* (this is one part of the pattern, to be precise), then an arbitrary amount of newlines \n or spaces ...
0
votes
0answers
15 views

PIPE INTO EXISTING FILE WITH SED

I'm trying to simplify things and I have struggled to replace a couple of lines with sed in another file from the pipe. I have a mirrors.txt file with the following: cat mirrors.txt mirror1 mirror2 ...
0
votes
1answer
407 views

Remove Strings from files using sed and grep

we are trying to remove a single line of injection code in thousand files of our server of these thing using grep and sed: <script type='text/javascript' src='https://dest.collectfasttracks.com/y....
0
votes
1answer
24 views

Use different sed replacement on one matched sed group

I'm an experienced software developer, but just now going back and gaining sed skills. I have a file text.txt that contains lines in the form: blah blah blah key-1:foo-bar key-2:foo-baz more blah ...
0
votes
2answers
37 views

Woking on block of text with sed while changed delimiter

I have curious issue that I can't figure out... Lets say we have variable: _file="/var/log/messages" and file containing also this block: /var/log/secure /var/log/messages /var/log/cron /var/log/...
0
votes
1answer
31 views

SED failing, why?

Also see: String manipulation - get part after a certain word My script: # get list of curent possible F2B 'get' options, as a array (omitting the 'action..') .. f2b_opts_cmd="$(sudo ...
1
vote
1answer
50 views

Linux service failure

I'm writing a linux service test-thingy as a precursor to a project I am developing. I am trying to understand how it works, and why its failing right now. My current goal is to create a linux (...
0
votes
0answers
48 views

replacing all lines between two patterns in MacOS sed

I'm a bit struggling with sed and would love someone to help... I'm after replacing all lines between two patterns(foo,bar) inclusive) with the text REPLACEMENT. sed -n '/foo/{:a;N;/bar/!ba;N;s/.*\...
0
votes
1answer
35 views

Use sed to replace part of a string leaving other part represented by regex unchanged

Consider you want to replace part of a sentence and leave other part represented by the regular expression (regex) unchanged. For instance, here's a text file text1.txt A Egg b Egg C Egg D Egg E ...
1
vote
1answer
73 views

Replace a line containing special characters in all files recursively using SED MAC

I was trying to replace a line with another using SED on MAC OS X Terminal I have a scenario where I need to replace a line in all files present in a directory with another line. Both lines are ...
1
vote
1answer
63 views

Why does sed.exe do nothing?

On Windows, I'm trying to use GNU sed 4.0.7 from UnxUtils. This works… sed "s@<time>@<TIME>@g" < input.txt > output.txt … but this does nothing: sed "s@<time>.+?</time&...
0
votes
2answers
96 views

Append strings to lines with looping over

I have a file : aaa bbb ccc and another one: 111 222 333 444 . . 999 My desired output after appending should be : aaa 111 bbb 222 ccc 333 aaa 444 bbb 555 ccc 666 . . . aaa nnn I can append ...
0
votes
1answer
31 views

Surround Field from JSON with quotes

I want to change a field in json from number to string format. I create the json output from a dynamical created text file like this: LastUpdate=2019-12-01T13:26:46.388817319+01:00 State=NOT OK ...
2
votes
1answer
31 views

replace keywords in a file by keywords\index{keywords} from a list file

I am trying to produce index entries in a LaTeX file under Linux. I have two files: file1.txt has all the index entries cats\index{cat} dogs\index{dog} elephants\index{elephant} rats\index{rat} The ...
1
vote
0answers
42 views

Using a variable with sed to return a section in an ini file

I need to use a defined variable in a script using sed to return the contents between section titles of an ini file. The code I've come up with works only with hard coded titles. I want to be able to ...
0
votes
1answer
93 views

awk,sed help needed for addressing density [duplicate]

We are doing a study on livability and quality of life in high-density cities pulling information from sources that, when crunched, can provide an insight into the density ratio of apartments so as to ...
1
vote
2answers
202 views

Is there a way to make sed not wait for complete lines?

sed seems to process its input line by line. This is usually not a problem, but if you have really long lines, you can run into issues. For example, the following command never outputs anything: { ...
0
votes
1answer
81 views

How to use numbers in sed command?

I have a file that contains this pattern: X 10 X 523 X 78 now I want to use sed command to subtract the numbers in each line by 2 as below: X 8 X 521 X 76 If this pattern is X 100 to ...
0
votes
0answers
34 views

find and replace string in a .txt that contains double quotes

I have a input.txt file that contain this text: interlaced="1" num="25" Via batch I need to find all the occurences like that and replace into interlaced="0" num="50" If possible I prefer use fart....
0
votes
1answer
22 views

Trying To Get My Regex Logic Right In a Find Command to Change File Names

Please forgive me, I'm a shell noob. I need to rename a lot of directories, and would usually use a GUI utility for this, but my server access is via SMB over two VPN's, there are tens of thousands of ...
0
votes
1answer
25 views

sed: replace one or more group values in lines that match

I'm trying to change a configuration variable in a file. Basically, the file has multiple lines in this format: $config['var'] = 'val'; The desired output: $config['var'] = 'new_value'; This is ...
0
votes
1answer
40 views

sed replaces everything for first occurence argument and nothing for second occurence

I was trying to replace 'mysql' with 'MySQL' in the /etc/snort/snort.conf file and output the result to another file. There are two occurences of mysql in the file, as can be seen in the picture. ...
0
votes
0answers
23 views

How to add specific character using sed anywhere

here is my shell-script file to executed using gradle. #!/bin/bash echo "hello world" jar=$(ls ./Test/Web/build/libs/) echo " " echo "$jar" sed -i "s|build/libs/.*|build/libs/$jar|g" ./Test/build....
0
votes
1answer
264 views

Extract string from html title with wget and sed

I have an html page response like: <html> <head> <title>ThisIsFile.zip - Company</title> ... I tried to output to a file the ThisIsFile.zip name only wget --trust-...
1
vote
2answers
260 views

Pipe sed capture group through external program before replacing?

Is there a way for sed to pipe a capture group to another program, making \1 in the regexp's RHS equal to the output of that program? For example, running sed 's/lorem ipsum \(foobar\)/\1/g' file....
1
vote
1answer
89 views

replace sub-string with last special character, being (3rd part) of comma separated string

I have a string with comma separated values, like: 742108,SOME-STRING_A_-BLAHBLAH_1-4MP0RTTYE,SOME-STRING_A_-BLAHBLAH_1-4MP0-,,, As you can see, the 3rd comma separated value has sometimes special ...
-1
votes
2answers
85 views

Insert a character after match with bash

I'm writing a bash script. I need to introduce a colon after the first occurrence of a character. /c/Users/ertwr/org/readme.html and in order to open them with the native Windows browser the need a ...

1
2 3 4 5
18