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
702
questions
0
votes
0
answers
43
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 ...
0
votes
4
answers
402
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 ...
0
votes
1
answer
84
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]....
1
vote
1
answer
214
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 "...
0
votes
1
answer
174
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}
0
votes
1
answer
25
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 ...
-1
votes
2
answers
231
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/...
1
vote
1
answer
91
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 ...
0
votes
0
answers
18
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 ...
2
votes
1
answer
162
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
...
5
votes
2
answers
757
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 ...
1
vote
1
answer
95
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 ...
1
vote
1
answer
1k
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 ...
1
vote
2
answers
331
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;
& -...
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
...
-1
votes
2
answers
714
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
// ...
0
votes
1
answer
2k
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</...
2
votes
1
answer
431
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....
0
votes
1
answer
401
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 --&...
0
votes
0
answers
273
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....
0
votes
1
answer
2k
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 (...
0
votes
1
answer
15
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 ...
1
vote
1
answer
68
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 ...
-1
votes
2
answers
160
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-...
0
votes
2
answers
46
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=...
0
votes
1
answer
89
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 ....
0
votes
1
answer
118
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 ...
-1
votes
2
answers
810
views
Using Sed to remove part of FASTA file header
I'm new to Sed and want use it to remove part of FASTA file header
My headers take the form:
CYTC2889-12|HM036578|Homo sapiens
and I need them to be:
CYTC2889-12|Homo sapiens
So far I have (running ...
1
vote
1
answer
56
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 ?
0
votes
2
answers
166
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" "$@&...
4
votes
1
answer
1k
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 ...
2
votes
1
answer
347
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'/...
1
vote
1
answer
368
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 ...
0
votes
0
answers
263
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=*/ ...
6
votes
4
answers
4k
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.
...
2
votes
4
answers
832
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:
...
1
vote
2
answers
894
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 ...
1
vote
1
answer
336
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 ...
-1
votes
1
answer
318
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-...
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 ...
1
vote
1
answer
877
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")
...
1
vote
1
answer
816
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&...
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/...
5
votes
3
answers
949
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 ...
2
votes
1
answer
24
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 - ...
3
votes
2
answers
840
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 /...
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:
...
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 ...
0
votes
2
answers
234
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 ...
0
votes
1
answer
34
views
removing entire line with sed using wild characters
E219 E36 C5X
C201 C19 C5X
E229 E36 C5X
E239 E36 C5X
C311 C19 C5X
In this file example, I need to remove all lines containing C[0-9][0-9][0-9]. How I can do this with sed command? The ...