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
5 votes
2 answers
402 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
64 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
215 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
119 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
  • 355
1 vote
2 answers
595 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
226 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
721 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
  • 189
2 votes
1 answer
205 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,006
0 votes
1 answer
129 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
216 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
603 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
  • 166
0 votes
1 answer
14 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
34 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
78 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
  • 47
0 votes
2 answers
42 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
52 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
45 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 votes
2 answers
466 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 ...
compbiostats's user avatar
1 vote
1 answer
33 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
  • 61
0 votes
2 answers
91 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
3 votes
1 answer
588 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
232 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
0 votes
1 answer
191 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
  • 101
0 votes
0 answers
197 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
3k 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
  • 543
2 votes
4 answers
798 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
0 votes
2 answers
442 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
  • 283
1 vote
1 answer
275 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
231 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
1k 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
625 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
0 votes
1 answer
469 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
  • 115
0 votes
1 answer
2k 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
5 votes
3 answers
905 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
22 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
  • 830
3 votes
2 answers
625 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
2k 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
2k 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
141 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
0 votes
1 answer
29 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 ...
deepblue's user avatar
  • 284
0 votes
6 answers
314 views

delete 50 random rows in a txt files that have their second column labeled as 0

I want to use the terminal commands for deleting 50 random rows from a txt file that is tab separated and has these sample rows where the second column is 0. The value in the second column is either 0 ...
Mona Jalal's user avatar
  • 4,239
0 votes
3 answers
1k views

How to add quotes to second element of a string after comma in a text file bash

File contents: 1234,/Product/number 234567 2456,/Product/number 456789 and so on...many lines Want the the output as follows: 1234,"/Product/number 234567" 2456,"/Product/number 456789&...
donna_unsworthcomcastnet's user avatar
0 votes
1 answer
798 views

using sed command to give variables with echo

We are trying to use the sed command to give back contents from 2 files (file1q and file1a) - a question and answer file. The question and answer file are the same with numbers on each line: 1 2 3 4 ...
robot010101's user avatar
0 votes
1 answer
160 views

Ubuntu Wordpress server tutorial error

I am going through the WordPress installation tutorial from Ubuntu Tutorials and I have typed this command as part of Step 6: sudo -u www-data sed -i ‘s/database_name_here/wordpress’ /srv/www/...
Jharris1's user avatar
0 votes
1 answer
433 views

sed and quotation marks

I get data files that contain both of these (with the commas and the quotation marks) ,"ncal", ,"NCAL", I want to replace all occurrences of ,"ncal", with ,"NCAL&...
Dan Murphy's user avatar
0 votes
2 answers
351 views

sed with ANSI color escapes fail

I do not know why this does not work: echo -e "$(echo "This is an uncolored text" | sed "s/{This is an uncolored text}/{This is an \033[0;34uncolored text\033[0m}/g")" ...
Bruno Peixoto's user avatar
1 vote
1 answer
131 views

Appending text, written in variable, below current line using sed

I can append text below current line, using the sed editor: $ foo=bar $ echo "some text"|sed "a\bar" some text bar But when I try to append text from variable below current line, ...
Josef Klimuk's user avatar
  • 1,546
4 votes
2 answers
4k views

Using sed with a variable inside double quote

I have a file input.xml which contains a line: <exciton lambda="1" fix="hole"/> in that line I want to replace 1 with 2 but I can't use just 1 as key word since there are ...
Jatin Kashyap's user avatar
-1 votes
1 answer
53 views

Filter blocks of log-output from a log stream

Here's my task: I've got a source stream of live log output from a messaging process. Lots of output is irrelevant to me but there are sections i want to collect and evaluate separately. Those blocks ...
Andreas's user avatar
  • 179
3 votes
1 answer
700 views

Replace a text within single quotes with another string using sed(just a first occurrence of regex)

I have a file with the following content: $ cat file.txt CREATE COLLATION public.collation123 (provider = libc, locale = 'fr-FR'); CREATE COLLATION public.collation_1 (provider = libc, locale = 'bas'...
Chander PRabh Jain's user avatar

1
2 3 4 5
14