All Questions
Tagged with command-line sed
352
questions
2
votes
2
answers
583
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
...
0
votes
4
answers
814
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
128
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
248
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
37
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
337
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/...
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 ...
2
votes
1
answer
178
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
815
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
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 ...
1
vote
3
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
913
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
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</...
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 ...
2
votes
1
answer
413
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'/...
0
votes
0
answers
283
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=*/ ...
2
votes
4
answers
865
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
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 ...
-1
votes
1
answer
339
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-...
1
vote
1
answer
1k
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&...
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
261
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
41
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 ...
0
votes
6
answers
369
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 ...
0
votes
1
answer
1k
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
...
0
votes
2
answers
707
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")"
...
1
vote
1
answer
146
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, ...
4
votes
2
answers
6k
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 ...
0
votes
0
answers
88
views
Using sed or awk to remove near-duplicates
I currently use the following to get as close as I can do to a file
cut -d ' ' -f 3- /var/log/issues.log | sed -E 's/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}//g' | sort -u
So far it gets rid of ...
3
votes
1
answer
11k
views
Apply sed operations only to lines beginning with a particular string
I have the following file format
Received from +11231231234 at 2021-10-10T19:56:50-07:00:
This is a message that contains words like from, at, etc.
Sent to +11231231234 at 2021-10-11T06:50:57+00:00:
...
0
votes
1
answer
74
views
Find command from left to right and attach ID
I am trying to match MRI files with their volume files.
Background:
Link to files: https://wiki.cancerimagingarchive.net/pages/viewpage.action?pageId=68550661#68550661171ba531fc374829b21d3647e95f532c
...
1
vote
1
answer
59
views
Making folders when the names have "/" and " ' "
I'm building up file paths (and mkdir-ing them) based on variables:
mkdir "$root_folder/$title ($year)"
I came across a situation where $title was 9/11: Inside the President's War Room. The ...
1
vote
1
answer
230
views
Sending bash script variables to sed
first time poster here and I searched for quite some time but didn't find a thread I could understand well enough to solve my problem.
I have a loop in my script that generates certain variables via ...
0
votes
1
answer
385
views
Why is renaming files with sed and mv printing '$'\r'
I am using Ubuntu on a Windows 10 machine. I am trying to rename 5 files (file1.txt, file2.txt, file3.txt, file4.txt, file5.txt) so that each file is replaced by Sample#_VoucherID.fastq.gz.
To do this,...
2
votes
1
answer
15k
views
Sed for replace a substring inside a string with a pattern
I am trying to replace a part of a pattern, such as, if I have col(3,B,14), after applying the sed command, I would like to get col(3,B,t14) which adds the t character to the third parameter in the ...
1
vote
1
answer
155
views
Sed for replacing pattern
I would like to replace a pattern, which consist of a var surrounded by () with sed. The next command success :
echo "This is the pattern : th_now(5, almost done!" | sed "s/th_now($var/...
2
votes
2
answers
2k
views
How to write complex sed query which got special char
I am struggling to replace a string with a special character. I am using the command below and I tried to escape each special character, but I am still getting an error.
If I don't use special ...
2
votes
2
answers
1k
views
Nested Command in sed substitution
I'm trying to used sed to find and encrypt ansible_password field in an inventory file and encrypt it with ansible-vault command. But ansible-command is failing throwing an sed error, where as a ...
0
votes
1
answer
453
views
Weird output while using sed to rename files
I am using Ubuntu 20.04.2 with GNU sed version 4.7. I have a bunch of music files that got named weirdly because they did not have all the info I specified to be in the file name. For example, "...
-1
votes
1
answer
2k
views
find: paths must precede expression: `.'find: possible unquoted pattern after predicate `-exec'?
i need to execute in background this command
sudo find '/abc/abc/' -type f -exec sed 's/domain1\it/domain2\com/g' '{}' \; . &
but I have two issues:
find: paths must precede expression: `.'
find: ...
0
votes
3
answers
278
views
Batch Rename DIrectory Using Pattern Matches
I would like to change this directory structure to the one following it. Although another directory batch rename question exists, this one is quite different.
l
'001. Aretha Franklin - Respect.mp3'*
'...
0
votes
0
answers
33
views
Caching the last 3 values of a variable isn't working inside script
My goal is to cache the value of a variable, going three times into history. So:
path=value3
cache1=value3
cache2=value2
cache3=value1
----------------
path=value4
cache1=value4
cache2=value3
...
1
vote
1
answer
180
views
sed edit string between spefic paragraph in a file
I hava a file called a.txt. And it contains the following contents. It's unknow how many lines between each function.
function a(
line 1;
line 2;
line ...;
properties pro = "test";
)
...
0
votes
1
answer
400
views
How to "timeout" a function so that it only runs once every 5 seconds eventhough it is called multiple times per second
See below:
still_notify=false
has_been_notified=false
notify()
{
$has_been_notified && return
watching=$(if [[ $(GET http://$ipplexserver:32400/status/sessions?X-Plex-Token=$...
0
votes
1
answer
48
views
How to replace text from a match (but not every match)?
I want to replace AllowOverride None from the group that has /var/www/ path. I'm using sed to do this but it's replacing every match.
apache2.conf before running the script
<Directory />
...
0
votes
0
answers
116
views
sed - trouble using a variable which is previously set with another variable
I would like to know why sed does not work when the value is set in var, $thecolor ?
(I cannot use an HTML parser for this).
The desired result is available without using a variable to set $...
2
votes
1
answer
198
views
Bash script to update BIND ACL - unwanted character
I am trying to update a file on a server where the new line needs to have a single tab at the front but new to bash scripting and sed and keep getting an unwanted character at the front.
This is the ...
0
votes
2
answers
740
views
How to replace string with file contents which contains symbols using sed
I have one word in one of my files and I want to substitute that word with xml file contents. considering that xml file contains some symbols which sed isn't able to process the command I am using isn'...
2
votes
2
answers
4k
views
Using sed to replace multi-line strings in apache2.conf file
As part of my Bash server setup script, I am trying to lock down the default apache www website.
I want to convert this:
<Directory /var/www>
Options Indexes FollowSymLinks
To this:
<...