Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [sed]

Sed is known as a Stream Editor in that it can carry out various filtering and/or transforming functions on standard input or on user specified files. It is commonly used to search-and-replace in text files. If your question is about text-processing, this tag is likely to be appropriate

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

bash/sed replace string of repeating string within a string

I have a file where each line represents data that may be encompassed with a string like "o o ". I need to replace the string between the encompassing characters with another string. The &...
SprRdHwk's user avatar
2 votes
2 answers
473 views

How to replace a file path with whitespace using sed?

I have many different files with a string in them. I need to replace this string with a path, although the path contains whitespace. So far, I have this: for a in files_[a-z][a-z]_all\.conf ; do ...
Spaghetti's user avatar
0 votes
0 answers
137 views

libinput Ubuntu 22.04 question for touchscreen calibration

I have inherited a process that used Evdev as the touchscreen driver, It is from 7 years ago at least. Running on a Panasonic Toughbook. This is for touchscreen calibration. The issue is now we are ...
Rich S's user avatar
  • 11
0 votes
4 answers
623 views

How to use sed to remove newlines above and below a string?

I'd like to change all occurrences of \ntoken1\n and \ntoken2\n to token1 and token2 in a file). I thought this would do it: ${ N N s/\ntoken1\n/token1/ s/\ntoken2\n/token2/ } but it does not. Thanks ...
John-L_.'s user avatar
0 votes
1 answer
125 views

sed mongodb connection string copying multiple times in env variable through github action

this is command which i run in github action its copying into .env.production file sed -i "s#DB_URI=.*$#DB_URI=mongodb+srv://xxxxxx:[email protected]....
DevOPs's user avatar
  • 11
1 vote
1 answer
240 views

Deleting lines beginning with a string

I wrote a bash script that I use to backup certain directories to the cloud. I then direct that output to a log file. The log file consists of lines starting with either "upload" or "...
Kenneth Odle's user avatar
0 votes
1 answer
344 views

How to use invert match regex in sed? like grep

How can I use invert match regex like grep -v ? I want invernt sed '/[Ss][0-9]*[Ee][0-9]*/d' ${Src} like grep -ev '[Ss][0-9]*[Ee][0-9]*' ${Src}
fsgdfgdfgd's user avatar
0 votes
1 answer
33 views

Ubuntu 22.04 LTS Nautilus Shows Locked sed* files that do not exist

After running a couple of thousand sed commands to make global file changes to my web site, specifically ensuring that every .html file is a valid HTML5 document, Nautilus shows that the folders that ...
James Cobban's user avatar
-1 votes
2 answers
297 views

How can I make output of sed command as variable?

How can I make the below command as variable ? I mean I need to assign this command to variable to use it within for loop. for i in $(sed 's|/home/bssuser/Scripts/Amany/log/bssuser/CDR/...
Amany Abd Elmnem's user avatar
1 vote
1 answer
156 views

How to pass a variable in sed command

I have declared a variable: username=user2 the contents of the test json is as follows: { "name": "user1", "city": "Texas" } I would like to replace the value ...
PRIYANKA S NAIR's user avatar
0 votes
0 answers
19 views

How should this sed command be rewritten to avoid an unterminated 's' command error? [duplicate]

I'm slowly following along with a Linux certification textbook just to bolster my skills a little. Text stream processing is the current topic, and the command I'm working with out of the book uses ...
runujhkj's user avatar
2 votes
1 answer
171 views

Multiply found text in sed - is it possible?

This is what I have: echo -e "a\t4\nb\t7\nc\t2\nd\t12\n" | sed -rn 's/(.*)\t([0-9]*)$/\2\t\1\1\1\t/p' 4 aaa 7 bbb 2 ccc 12 ddd This I want: 4 aaaa 7 bbbbbbb 2 cc ...
xerostomus's user avatar
  • 1,020
5 votes
2 answers
790 views

How to add double quotes around string and number pattern?

Hi I need to add double quotes in a pattern in 300k lines. I'm trying to use sed and I read multiple inquiries here and other sources, but I can't seem to understand its syntax. I have: chr1 ...
Thalles's user avatar
  • 51
1 vote
1 answer
96 views

Check a host file for modification and if missing add it

I'm using docker in which the container has its own /etc/hosts file. It gets cleared out when rebooting. I'd like to create a script to check for an entry and if missing add it. So if /etc/hosts has ...
Mark Vetter's user avatar
1 vote
1 answer
2k views

appending variable to end of file with sed

I have dates on the last line in files like this: 20230220 and I want to add hours like this: 2023022000 The hours are continuously assigned to a variable i in a loop. How to use sed inside the loop ...
CaosWT's user avatar
  • 11
1 vote
2 answers
383 views

How to delete emojis from Youtube filenames?

Im trying to remove emoticons from this Youtube filename: وسائل الاتصال الحديثة󾌧 📺 & 💻 😃 -eYrBcHOx2Jf.mp4 Im using perl -p -e 's/[^[:ascii:]]//g' and tr -dc '[:print:]' but got this; & -...
s3idani's user avatar
  • 363
1 vote
2 answers
2k views

awk or sed command to replace line break plus text containing spaces

An answer to another question suggests sed -i 's/original/replacement/g' file.txt to replace specific words in a text file. My starting situation looks like this: Item: PRF Type: File ...
Ray Woodcock's user avatar
-1 votes
2 answers
836 views

Remove last occurrence in a file with sed

I want to remove the very last occurrence of "(* cds_ams_schematic *)" in a file using sed command. `view schematic `timescale 1ns / 1ns (* cds_ams_schematic *) module ... endmodule // ...
Syed Tauseef's user avatar
0 votes
1 answer
3k views

How to use "sed" for replacing xml tag in multiple lines xml content on bash

I want to use sed to replace the XML tag on bash. Here is the example xml content for testing: <xml-content> <validation> <timeout>2880</timeout> <subject>example</...
stackbiz's user avatar
  • 329
2 votes
1 answer
472 views

replace uuid in a grub.cfg with sed

How can I replace a UUID in a /boot/grub/grub.cfg with sed? For some reason I have to replace string 88411b09-1aaa-4775-9fc7-f60041049d6c with f210c829-2c04-4963-9a78-d61cf8ebbd48 in a /boot/grub/grub....
nobody's user avatar
  • 5,497
0 votes
1 answer
605 views

End of line in sed command

I need to append some variable string at the end of every line in the file using the sed command. Let's say that $var is a variable string. If I use a single quote sed -i 's/$/$var/' inputfile.txt --&...
vipin kumar soni's user avatar
0 votes
0 answers
295 views

How to replace URLs from html to a file using grep, sed or any common tools?

I'm trying to replace URLs of my conf file from a HTML file because sometimes the URLs get updated/changed. I need a simple script that can fetch the HTML & update/replace the URLs in my conf file....
OrigamiOfficial's user avatar
0 votes
1 answer
3k views

Escape characters from a bash variable

I am trying to search-and-replace strings in a configuration template, using bash variables. Bash variables BACKUP_KEY="ABCDEFG" BACKUP_ROOT="/var/backup" Configuration template (...
BurninLeo's user avatar
  • 186
0 votes
1 answer
20 views

Need help to figure out a regex to modify some files

I have some files that I need to clean up some names. for example: GCA_940670685.1_Clostridium_sp_chr 3757330 GCA_940677205.1_Clostridium_colinum_chr 2035557 GCA_942548115.1_Aeromicrobium_sp_chr ...
Paulo Sergio Schlogl's user avatar
1 vote
1 answer
99 views

Bash script to return lines matching a pattern and then count them?

I'm trying to make a simple bash script to take user input and then search a .lst file for lines matching said input and then the count of matching lines. I'm pretty inexperienced with bash so I was ...
AstralV's user avatar
  • 21
-1 votes
2 answers
172 views

SED- replace result at file with anther one

I am trying to replace result at file with result of anther. Basically trying to replace ip address at netplan file,It does not work. this is the sentence: sed -i "s/$(cat /etc/netplan/00-...
HELLBOY's user avatar
  • 57
0 votes
2 answers
47 views

I can't change the value between two quotation marks with sed

How can I replace the word at the very end of the first line using sed? test00 ; test01 ; 'test02 -test03="j32h"' test04 The result should look like below; test00 ; test01 ; 'test02 -test03=...
w3tx75's user avatar
  • 3
0 votes
1 answer
101 views

Trying to add a line to my bashrc but it's not working

I am trying to add a line after I find some text to my .bashrc but I don't have my syntax correct. Can someone help me. I want to add the line "alias cls='clear' after the egrep line in the ....
r-c-man's user avatar
0 votes
1 answer
164 views

Replacing text with a string that contains (')

I want to replace a line inside a file with another one that contains 'something something'. I tried achieving so by sed and using the back slash but it didn't work. I tried 's/original/'something ...
Muzzamil's user avatar
1 vote
1 answer
64 views

How do you type a line containing a single dot (.) in ed?

\. doesn't work. a single dot (.) ends the command and cant be recognized. Please don't tell me; use sed or echo . >> file. Is there a way to do it with ed ?
Johny's user avatar
  • 71
0 votes
2 answers
185 views

sed is being confused by my replacement string

I need to change a single line in the file /opt/google/chrome/google-chrome exec -a "$0" "$HERE/chrome" "$@" to exec -a "$0" "$HERE/chrome" "$@&...
Ian Price's user avatar
4 votes
1 answer
2k views

Append the output of sed to a file

I have two scripted files, say file1 and file2. I want to take the content of file1, change character a to A in file1 and append the output to file2 without modifying the content of file1. I'm trying ...
Radagast's user avatar
2 votes
1 answer
389 views

Why does sed command output "char 5: unterminated `s' command"

I ran some command as below to debug my script but it was not work. $ L="Thanh,Fri 11 Nov, Mon 14 Nov,LX,VN" $ B="Fri 11 Nov, Mon 14 Nov" $ N="11.11-14.11" $ sed 's/'$B'/...
Thanh Nguyễn Xuân's user avatar
1 vote
1 answer
419 views

Using sed insert or append for ubuntu autoinstall

I use following command in my ubuntu auto-install late-commands to append a line in my /etc/aliases file: sed -i -e '/^postmaster:.*/i\'$'root: root' /target/etc/aliases I also tried POSIX ...
MaKaNu's user avatar
  • 111
0 votes
0 answers
276 views

SED find and replace not working as expected

I can't seem to get my sed bash commands working correctly. What am I missing? sudo sed -i '/^server-port=*/ c server-port=19132' /opt/bedrock_server/server.properties sudo sed -i '/^server-portv6=*/ ...
ausip's user avatar
  • 101
6 votes
4 answers
5k views

sed: couldn't open temporary file /etc/update-manager/sed2l1b5x: Permission denied

When I launch a Ubuntu terminal I have this error : sed: couldn't open temporary file /etc/update-manager/sed2l1b5x: Permission denied. The file sed2l1b5x is random each time I launch the terminal. ...
Sinedolo's user avatar
  • 623
2 votes
4 answers
851 views

how to separate each content in the file?

I have a text file (more then 1GB in size) and it contains lines like these: ...
maa's user avatar
  • 91
1 vote
2 answers
1k views

Sed (or other command) replace character range with hex codes

Let's say we have a file with non-printable characters. I would like to visualize those using their hex codes. Arte there a single liners that can achieve it, without writing a full-blown program. say ...
Dr Phil's user avatar
  • 293
1 vote
2 answers
400 views

Why is a simple sed command not working on the raw csv file I downloaded from an EXO instrument?

I have hundreds of csv files downloaded from an EXO instrument that I want to reformat. The first part of every file contains general information on the instruments followed by a table with header and ...
SophiaFeuer's user avatar
-1 votes
1 answer
328 views

What does this sed command actually do with those wildcards

lineNumber=$(dialog --inputbox "Enter the line number to update that line: " 8 60 --stdout) update=$(dialog --inputbox "Please enter the informations as 'name,surname,phone number,e-...
Halil Can Parlayan's user avatar
0 votes
1 answer
2k views

Using sed command to replace a line matching a variable with a new value that is stored in a variable in a file that is variable

I am trying to use the sed command to replace a pattern-matching line (lines starting with ">") with a new line that is stored in a variable and do the iteration for all the files in the ...
Sgt. Pepper's user avatar
1 vote
1 answer
922 views

How to insert a block of code inside a file based on specific pattern in Linux

I want to insert a block of code inside a file name build.gradle This is the block of line: signingConfigs { release { storeFile file("$keystorefile") ...
White Mask Guy's user avatar
1 vote
1 answer
929 views

Delete all lines from a line with certain string until another line with a diffrent string in a file

file.txt: start some text works "HELLO" foo test sum other end start som "other" line with text 'also' thing foo end and I want to delete the line in which "HELLO&...
NodeX4's user avatar
  • 125
0 votes
1 answer
3k views

Replace simple text in the end if line with sed

I have that text #!/usr/bin/env python and I want to replace python with python3 (without regex) but I want to make sure that this text in the end of line. I tried this command: sed -i 's/python\n/...
Kokomelom's user avatar
  • 103
5 votes
3 answers
956 views

How can I capitalise a word proceeding a specific word

Lets say I want to capitalise the first word following the word jumped. Example below Original text: the cow jumped over the moon Amended text the cow jumped OVER the moon I have tried awk and sed ...
yolo_techy's user avatar
2 votes
1 answer
25 views

insert variables from 2 files based on 1 row

I have 3 source files. 1.txt - template. <field name="COL1" label="COL2" data-source="COL1" classes="attribute" category="Attribute"/> 2.txt - ...
genderbee's user avatar
  • 850
3 votes
2 answers
878 views

Trying to uncomment unattended-upgrades lines with script, need help

I've recently started working as an IT person in a all Linux company, and noticed some of the tasks we do can be 'easily' automated. Today's task to automate is installing software and configuring /...
Marcos Delfino's user avatar
1 vote
1 answer
4k views

sed: -e expression #1, char 32: unterminated `s' command

I have a text file that has many groupid = []. I wan't to edit the specific line which is 41, How can I do it? My command: sed -i "s/groupid = []/groupid = [ 2 ]/" rights.toml I have tried: ...
Eyup's user avatar
  • 37
0 votes
1 answer
3k views

How do I use sed to replace with cat file content

I tried the following code, but it doesn't do what I want: echo "include(file.txt)" | sed -E 's/include\(([^)]+)\)/'$(cat $(readlink -f /tmp/$1))'/g' I need replace some special words with ...
flavraul's user avatar
0 votes
2 answers
251 views

How do I get variable substitution to work with this sed command

I have this script: PATTERN=xAB dd if=/dev/zero count=1 bs=10 | sed "s/\x0/\${PATTERN}/g" > test_ab hexdump -C test_ab output I get is: $ ./make_test 1+0 records in 1+0 records out 10 ...
arcomber's user avatar
  • 173

1
2 3 4 5
15