Questions tagged [sed]
"sed" ("stream editor") is a Unix utility that parses and transforms text files.
1,023
questions
3
votes
2
answers
485
views
How do I delete every ocurrence of a word that is followed by another, without altering the whitespace?
Suppose my file looks like this:
foo bar
foo bar bar
foo foo bar foo
What I want to do is delete every foo that is followed by a bar (i.e. there is only whitespace between them), without ...
0
votes
0
answers
31
views
ADATA SED SSD SX900
i have a ADATA SX900 256GB SSD and it has opal encryption on it. i can get into the SSD as i have the password, but i wish to deactivate the encryption, so i don't have to enter the password evertime. ...
1
vote
0
answers
37
views
Sed editing of large text file much faster than native bash substring replacement?
I have a ~19MB text file which I would like to perform many find/replace operations on. I originally wrote the script to loop over inplace sed operations e.g.
sed -i "s|$pattern|$replacement|g&...
2
votes
2
answers
74
views
What options are being used by sed to parse a file and write to new file
I am debugging a LINUX script that was written by someone else. In the script we have a line of code like below
sed -i "\#</resources>#{h;s#.*#cat /opt/abc/new.xml#e;G}" /opt/abc/...
1
vote
0
answers
83
views
pipe awk output in sed command
I have multiple lines in a file names.txt, let's say
my name is Jim your name please
what is good Harry potter
how is he Jhony and me
and so on , more than 500 lines.
I use awk command to search/ ...
0
votes
0
answers
91
views
bash loop to create m3u file with sed awk grep
I am trying to auto create m3u file for my IPTV software with the help of sed/awk or grep command,but don't have much experience in this. expert help required to do this. working on Windows-10 PC ...
0
votes
1
answer
52
views
Trying to search & replace within brackets using sed
I have a json file which among other settings, contains the following data:
"school": {
"name": "qwerty",
"key": "user",
"secret"...
0
votes
1
answer
167
views
sed: unterminated `s' command – What does it mean?
I'm just learning this sed tool. So bear with me and appreciate your help.
This works fine.
$ date | sed 's/ /_/g'
Mon_Mar_20_11:02:26_MST_2023
But not this one.
$ date | sed 's/MST/EDT'
sed: -e ...
0
votes
2
answers
84
views
How to combine tee, sed and grep?
I have a command after which I place | tee >(sed $'s/\033[[][^A-Za-z]*[A-Za-z]//g' >> ~user/filepath/file.txt) The tee is redirected to sed $'s/\033[[][^A-Za-z]*[A-Za-z]//g' which removes the ...
0
votes
1
answer
32
views
sed remove double quote pair spanning lines
In my OpenDKIM key file, I have extra quotes that can't go in "proper" DNS records. (I'm surprised the OpenDKIM devs allow this in their file, but that's another story.)
In RegEx, it is two ...
0
votes
1
answer
29
views
Linux - Find string and then end of section
I have an XMLTV file. I need to get all of the programme sections for a specific channel. An example snippet:
<programme start="2023031305000 -0400" end="2023031305300 -0400&...
0
votes
2
answers
33
views
How I can delete characters in text file lines using sed?
I have a text file containing urls.
1,https://cinesmovies/i/3juj2i,,
1,https://cinesmovies/i/3juj2j,,
1,https://cinesmovies/i/3juj2k,,
1,https://cinesmovies/i/3juj2l,,
I want to delete first 2 ...
2
votes
1
answer
32
views
How to remove similar elements from beginnign of each line in a text file using sed or similar?
I have text like this:
UgxJam3R6oHGHJMrbHx4AaABAg,,hqJGuSXaWcY,UCkhUJbKZIZsARJx7UsX7nw,NAME,https://URLYOUDONTNEEDTOSEE,2023-03-03T22:45:53,Sometextineed,1,false,0,
and I want to use sed or something ...
1
vote
1
answer
137
views
Add new content after specific string in text file using shell script
I want to add the below snippet after the string server { in nginx.conf file.
location /nginx-status {
stub_status on;
allow all;
}
The script below adds the snippet after server { wherever that ...
1
vote
2
answers
133
views
Delete lines between two patterns (with multiple occurrences) around a third pattern (single occurrence)
I'm trying to edit an uncompressed PDF on macOS Monterey, and I want to delete objects that contain a certain pattern in their description. Such objects start with "X 0 obj" (where X is the ...
1
vote
1
answer
39
views
How do I correctly execute 'vim $(grep -rli pattern | sed 's/\(.*\)/"&"/')' in bash?
I am trying to edit files that contain text matching a regular expression with vim and use the following command in bash to do that:
vim $(grep -rli pattern | sed 's/\(.*\)/"&"/')
I ...
0
votes
2
answers
64
views
How to group a flat list into categories and create a tab-separated value file using awk?
Crosspost: https://www.nixcraft.com/t/converting-a-list-into-a-tab-separated-file-grouped-by-values/4517
I have a text file with a list of values. The goal is to create a tab separated values file, ...
0
votes
2
answers
333
views
Remove comma and next 3 characters from line with sed
I'm writing a shell script to send fail2ban logs to a postgres database.
The event timestamps in the application log annoyingly shows the milliseconds of the event separated with a comma (like this: ...
0
votes
1
answer
301
views
Find and replace text in a file only after 2 different patterns match using `sed` or `awk`
This is an extension of the question asked-and-answered here: Find and replace text in a file after match of pattern only for first occurrence using sed
The problem being: I need to perform a find-and-...
3
votes
2
answers
355
views
sed: extract and print regexp match group
I'm trying to extract the IPv4 address of a network interface on Linux.
I have a working solution:
IFACE=eth0
ip a show dev $IFACE | sed -n 's/.*inet \(.*\)\/.*/\1/p'
For the record, here is a sample ...
0
votes
1
answer
319
views
Bash Script - sed command for color
I have a log file and I would like to highlight some key words when it display the output.
So I like the word, myaccount and myfile.txt to be a different color so it stands out. This is what I have
...
1
vote
1
answer
40
views
sed in bash: '-n' as input is treated differently?
I'm struggling with a problem with sed in bash which occurs both on macOS and Ubuntu. During a long debugging session I pinpointed it down to this minimal example:
echo "abcde" | sed 's/.*/x/...
0
votes
1
answer
27
views
how to use 'sed' in bash to delete a line from a specfic point on?
so i have these lines for example:
name,lastname,mail@gmail.com
name2,lastname2,mail2@gmail.com
i need to delete the 'mail@gmail.com' in every line
essentially i want to make sed do "delete ...
2
votes
1
answer
99
views
More robust than sed for find and replace
I need to replace some strings in a file programatically. As a minimum case, I'm showing here just replacement for |FNAME| and |LNAME|.
Currently I am using this for the task:
sed -e "s/|FNAME|/$...
0
votes
0
answers
77
views
sed for back slash and tab char has error "unterminated `s' command"
I have a line in the middle has a "\\t", a back slash following a tab. I need to replace it with '\t' just a tab
sed -i -r 's/\\\t/\t/g' a.txt
it gives an error:
sed: -e expression #1, ...
0
votes
1
answer
56
views
Why am I getting an error in my Bash script?
Wondering if someone could take a look and I keep getting errors when trying to execute this script. Can someone tell me the possible reason is?
Error
/volume1/Cameras/bv2.sh: line 5: syntax error ...
0
votes
2
answers
112
views
sed replacement by regular expression
I would like to achieve to generate with sed from following source:
my_component_name_with_underlines_9.5.6
my_other_component_name_with_underlines_8.7.1
following target strings:
...
1
vote
3
answers
3k
views
Remove the lines before and after the exact match - linux
I have a file like this in /etc/test/host.conf :
# this is a test
host = example.com
private = 192.168.1.1
# end of test
# this is a test
host = example.com
private = 192.168.1.2
# end of test
I ...
0
votes
1
answer
644
views
Find and replace the exact match in a file - change the value of something in a file - linux terminal
1) I have a file : /etc/testconfig/users.conf :
john1:*:$5$CJ5q52R0DPTbnvfddsa3IB/lofFuRoFnFc3OgKxkDP520PntI8pI76
john43:*:$5$cSV2tbDHA5645gdfN5w8W2TDMddyOPMBUR9nL7hQoVwF6QddElClKji/PB
54john:*:$5$...
0
votes
1
answer
26
views
How to Change Usernames in Password Store en Masse
I have been using pass for to store my passwords via GPG. I am trying to change an old username to a new username in dozens of accounts all at once.
Each username is in a "Username:" comment ...
-1
votes
3
answers
735
views
sed or grep command to extract all lines that match a particular date and time range
2022-09-08T08:55:10+02:00
2022-09-08T19:55:16+02:00 200 200 76 0GET /v1/heartbeat/tcanalytics HTTP/1.1
2022-09-08T23:55:17+02:00 200 200 POST /...
0
votes
1
answer
215
views
Replace Host URL including square brackets
In Ubuntu 18.04 I am trying to replace a line hosts: ["localhost:9200"] with hosts:"http:xx.xx.xx:9200" by using the below command but it's not getting updated in the target file.
...
0
votes
1
answer
153
views
Can I double every text line of a file using sed in linux bash?
Can I double every text line of a file using sed in linux bash?
Example file:
aab1
aac2
awq6a
azs4
What i want:
aab1 | aab1
aac2 | aac2
awq6a | awq6a
azs4 | azs4
I know about "read line" ...
0
votes
0
answers
46
views
Take a screenshot and then upload the image to imgur through terminal with .zshrc?
I am interested to the accepted answer of this question: "How to take a screenshot and then upload the image to imgur through terminal?" but with Oh-my-zsh and with .zshrc config file ...
-1
votes
2
answers
446
views
Convert CSV to text and automatically remove quotes and a specific word - Linux
I need to convert .csv to .txt format via CL (Command line) and automatically remove quotes and a specific word - Linux.
Example:
I have multiple exported csv files that have:
At first row I have: &...
2
votes
0
answers
272
views
Find and replace multi-line block in multiple files (bash/linux)
I'm trying to find a way to find a text block that meets the criteria:
block starts with "google = {"
block ends with next "}" character found - ignoring everything else.
Example
...
0
votes
1
answer
396
views
Sed Regular expression to extract MAC address from file
I would like to know what are changes I need to make to my regular expression to work with 'sed' in Linux (actually, I am working with (GNU sed v4.8) in OpenWRT).
I have a file containing a list of ...
1
vote
0
answers
132
views
Compare two large text files with NO newlines
I have two large (2-3MB) text files with only a few hundred characters different. Normally diff would work fine for comparing them to find the differences. But although it's a text file, there are NO ...
0
votes
1
answer
553
views
Replace strings from text file with csv values
I've got a txt file (template.txt) with stuff like:
Hostname from Client: !hostname . OS !windowsversion
and a CSV-Export from many clients:
!hostname, !windowsversion
exampleName, Windows10-Pro
I'm ...
0
votes
3
answers
142
views
Copying files in order by last modified
I'm trying to move a bunch of files from a directory to my phone in a specific order so it wouldn't mess up the order in my phone.
The furthest I've gotten is by using this command:
find . -printf &...
0
votes
1
answer
5k
views
How to find and replace string include special character with sed command
I have a file with content like this:
deployment.yml
spec:
containers:
- name: atl-lead
image: "registry.it.zone/api/dev/atl-x:1.2.0-SNAPSHOT-110"
imagePullPolicy: Always
I want ...
1
vote
1
answer
85
views
get the top urls from the logs
I have a numbers of log files:
adsfs.demo.com_2022-07-11-0000-0001_cn.tgz
adsfs.demo.com_2022-07-11-0000-0002_cn.tgz
adsfs.demo.com_2022-07-11-0000-0003_cn.tgz
adsfs.demo.com_2022-07-11-0000-...
0
votes
1
answer
237
views
Capture process output with sed, capture block of text and then filter inside it
There is some stdout that I would like to filter with sed but I don't know how. The stdout example would be:
.
.
.
Model a. # This should be captured
.
.
.
Metrics results: # This ...
0
votes
1
answer
2k
views
Pattern match in next line and replace using sed
I have file containing following data
cat file:
ABC
+123
+456
XYZ
+789
I want to search "+" at start of next line and remove "+" and concatenate with current line
Output should ...
0
votes
1
answer
141
views
Detect files with multiple extensions
I've a synology running a kind of linux OS.
I've transfered there a lot of photos.
Unfortunately, some are with .jpg and some with .JPG depending of the tool I used to import.
These are considered as ...
0
votes
2
answers
475
views
sed replace every character in match with single character like █████ redaction
Is there a sed replace function (or other Regex) that will replace every character caught by the match pattern with a single character that is meant to overlay or REDACT the matches? For instance the ...
0
votes
1
answer
45
views
Insert new line if file contain string
I need to insert 'import packagename' to the line after imports. In files which contains the specific word.
What I try:
find iOS/Chat \
-type f \
-name "*.swift" \
-exec gsed -e "/...
0
votes
1
answer
654
views
Inserting string between two known strings with sed or awk
I've used sed a bit before in the past for updating strings but I haven't been successful with inserting a string in between two known strings.
I attempted to use this but it didn't update anything.
...
0
votes
1
answer
105
views
Unknown command: `C error displayed when using SED to delete a line in shell script
I am running the below command in a while loop. If my line matches my scenario it will delete that line. I have 2 example 1st one working 2nd one fails.
Can someone point out my mistake?
Example 1 :
...
0
votes
1
answer
599
views
Can encryption from Self-Encryption Drive (SED) be removed?
Can the actual encryption process be removed? Not the Authentication Key (AK) but the actual process embedded in the disk. Per my understanding it cannot be removed but I am confused with this post ...