Questions tagged [sed]
"sed" ("stream editor") is a Unix utility that parses and transforms text files.
1,041
questions
-1
votes
3
answers
1k
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
299
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
382
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" ...
-1
votes
2
answers
1k
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
740
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
850
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
258
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
987
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
207
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 &...
1
vote
1
answer
11k
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
156
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
418
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
3k
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
207
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
915
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
136
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
851
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
160
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
1k
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 ...
0
votes
2
answers
4k
views
How to group and count all lines in a file that contain specific string
I want to filter all lines from a file that contain mySearchString and after that group them together and count them.
Example find all lines that contain 9791
AB-9791___Foo
AB-9791___Foo
DE-9791___Bar
...
0
votes
1
answer
45
views
keep each line containing x only if column y is the first containing x. remove the rest containing x
I'm trying to reduce a results file that contains multiple results for sometimes the same query and I only want the top result from each query.
Using bash and bash tools like awk, sed, etc. I would ...
0
votes
1
answer
252
views
sed remove with regex
I have code that contains
#ifdef CEEDLING_TESTS
void scheduler_task_delay_update(uint8_t task_index) {
#else
static void scheduler_task_delay_update(uint8_t task_index) {
#endif
I want to remove ...
1
vote
1
answer
2k
views
Sed match and replace only certain characters
I have mutliple strings in very similar format.
(#1111111)
(#4444444)
I was trying to use sed to provide an output:
1111111
4444444
I have tried:
sed 's/(#[0-9]+)/^[0-9]+/g'
which seems to match ...
0
votes
1
answer
185
views
Removing Duplicate from File
I have two files fileA and fileb
FILEA
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
5.5.5.5
FILEB
4.4.4.4
2.2.2.2
Output should be
1.1.1.1
3.3.3.3
5.5.5.5
Size of File A is around 60GB and Size of File B is 1GB
...
0
votes
3
answers
1k
views
sed will not execute as a ssh remote command
I'm working on a script that lets me delete old public keys from a server via ssh.
The issue seems to come from the formatting of my ssh command here:
ssh -qo ConnectTimeout=20 "${user_ssh}@${ip}&...
0
votes
1
answer
144
views
Replace string from and including '_' up to excluding ':' script? [duplicate]
I am trying to remove a string from and including one char, '_' up to but not including another char, ':'. Everything is on the same line.
I have files with different names and numbers, that contain ...
0
votes
1
answer
394
views
How do I use sed to parse a string that includes hyphens?
Input example:
foobar_1-1 1024 x 1024
Desired output
foobar_1-1
The hyphen is causing issues here. It's causing the output to be two items in the array:
foobar_1, 1
Any advice?
-1
votes
1
answer
2k
views
Remove everything between 2 chars using sed
I am trying to remove a string from and including one char, '_' up to but not including another char, ':'. Everything is on the same line.
I have files with different names and numbers, that contain ...
0
votes
1
answer
935
views
Append a line to the end of the file using ssh, sudo and sed
I have an obvious problem with quoting in bash such that I couldn't really solve for a while. Here is a loop with executing a remote command in a sudo-subshell on a remote server via ssh:
for HOST in $...
0
votes
1
answer
263
views
Piping PCRE grep into sed
I wanna sed this file, but the BRE in sed is not working as well as I hope.
What I have now is basically just :
$ cat Dungeon | grep -P -o '<\/.*?>'
My question is how do I sed this? I want to ...
0
votes
4
answers
299
views
Shorten a text that is too long (with sed?)
I have the following example of a .csv-file
"0a","1a","Short text","abc"
"0b","1bx","Here is a very long text","def"
&...
1
vote
1
answer
238
views
How do I replace both matching patterns in a line using sed?
TL;DR
Given this:
$ echo "-lngtcp2_crypto_openssl -lnghttp2.14 -lnghttp2 -lnghttp3.0" | \
sed "s: -lnghttp2[^[:space:]]* : lib/libnghttp2.a :g"
-lngtcp2_crypto_openssl lib/...
-1
votes
2
answers
1k
views
I have a list of searching word. How to replace them in another file?
I'm sure this question is asked multiple times, but I fail to find it. Basically I have a text file, and a list of all search strings (e.g. cat, dog, banana, etc). I want all occurrences of those ...
0
votes
1
answer
50
views
Regex with first line
I want to search inside the but replacement the firsh character of line.
for example, line is this
pool 0.ubuntu.pool.ntp.org iburst maxsources 1
I want to search pool.ntp.org add firsh character #
...
0
votes
2
answers
411
views
GNU Sed breaks with tab a a delimiter?
I am wondering what is going wrong here. Using a space as a delimiter works but with a tab it seems to fail.
% sed --version
sed (GNU sed) 4.8
Copyright (C) 2020 Free Software Foundation, Inc.
License ...
0
votes
2
answers
608
views
Remove the file name from a messy path in a text file awk or sed
I have an xml file with many lines containing something like this:
Save="C:\Users\Administrator\Desktop\my files\1020\A54f\Drawing965.DWG" Module="0"
Save="C:\Users\...
0
votes
1
answer
4k
views
BASH converting txt to csv
BASH/scripting newbie here.
sed 's/ \+/,/g' output3.txt > output.csv
This one gave me so many delimited.
I only one to delimit the "pipe" | symbol and leave the rest as it is. So ...
1
vote
1
answer
2k
views
How to best use SED to comment out a config value while adding a new config value right after it?
I want to edit some config files on in the CLI without a wysiwyg editor but instead using sed.
Is there a best practice for doing that?
Here are a few examples of what I mean:
Config file example 1
A ...
4
votes
3
answers
9k
views
Find and replace text in a file after match of pattern only for first occurrence using sed
Let's say I have the following input file:
Server 'Test AB'
option type 'ss'
option port '1234'
option timeout '60'
Server 'Test CD'
option type 'ss'
option port '1234'
option ...
1
vote
0
answers
75
views
use bash script to remove tracking from google scholar links into non tracking links for wget
I Get regular google scholar emails. I am trying to make a simple script that lets me download the pdfs / articles, without google tracking me via their urls.
Up till this point I have been copy ...
0
votes
1
answer
2k
views
How to replace a line in sed with unknown amount of whitespace?
I would like to replace a line in a config file with sed. But the line I am trying to replace contains an unknown amount of whitespace:
conf is foo
conf is bar
config is foobar
I've ...
8
votes
2
answers
2k
views
Emptying HTML tags with sed
I want to empty the content of every HTML tag but "keeping the structure".
From:
<h5>Holdrs <div class="tooltip" data-tooltip="Accounts with ..."></div>&...
0
votes
1
answer
257
views
Match pattern and any character after up to space, and rearrange captured patterns with sed
I would like to find a particular pattern (k__), and any characters after it, up to a space, and then move that captured pattern to the end of the line
With this example file:
cat test.file
37099 ...
0
votes
1
answer
258
views
Pipe Output of dhclient with sed
Goal
Limit output of dhclient.
Code
dhclient eth0|sed 's/answers//'
expected behaviour
RTNETLINK : Operation not permitted
got
RTNETLINK answers: Operation not permitted
Piping ifconfig works
ifconfig ...
-1
votes
1
answer
2k
views
sed RegEx matching for full/partial string
I'm having some trouble creating a RegEx string for sed.
I tested the expression with various online services, and there, it does succeed.
But not so with sed, unfortunately.
This is my testing sed ...
2
votes
1
answer
1k
views
Using the output of a piped sed for the replacement value of a second sed
I am trying to get the version of a npm package, and use it to replace the value in another file. Specifically, I want to get the package.json version and use that to replace the wordpress style.css ...
2
votes
1
answer
2k
views
Batch removing specific text in .txt files
I have 30+ text files that I want to remove specific lines of text from.
They all have different names (which I need to keep), they are in the same folder. The text will not all be on the same line ...
0
votes
2
answers
573
views
How can erase first character of all string in file
How can erase first character of all string in file if this is zero?
e.g
I have file
$ cat file
01111111 01222222 6666066
09999011 02222044 0743333
01000000 30000000 2222220
Try with sed command ...
0
votes
1
answer
528
views
BASH - How to combine data from 2 files
I have 2 files with the following data
file1:
datapoint1name##datapoint1name
datapoint1name.PercentUtilization=
datapoint2name##datapoint2name
datapoint2name.PercentUtilization=
datapoint3name##...
0
votes
2
answers
3k
views
Delete pattern matching regex from sed capture group
I'm trying to remove all instances of '_(one number)' from certain strings in a file. So tig00000003_1 should become tig00000003 This is what my test file looks like:
##sequence-region tig00000001_732 ...