All Questions
363
questions
1
vote
1
answer
66
views
How to merge all mp3 files located in the same directory?
The command below used to work but stopped around ubuntu/kubuntu 20.04.
ls *.mp3 | sed -e "s/\(.*\)/file '\1'/" | ffmpeg -protocol_whitelist 'file,pipe' -f concat -i - -c copy output.mp3
...
0
votes
2
answers
104
views
bash + how to insert date before line
lets say I want to pipe the date output in the beggining of some text
for example
echo "this line is test line" | date
and expected output should be
Wed May 22 14:55:10 UTC 2024 this line ...
0
votes
1
answer
33
views
sed does not consume rest of the line
I have one line of different words stored in a txt file
N/A 9.0 Yes Yes N/A N/A N/A N/A 8.8 Yes Yes N/A N/A N/A N/A 8.7 Yes Yes N/A N/A N/A N/A 9.2 Yes Yes Yes Yes Yes Yes 9.1 Yes Yes Yes Yes Yes Yes ...
-1
votes
1
answer
74
views
Search and replace doesn't work with sed busybox. getting sed: unmatched '/' error
I am trying to search a particular string and replace all occurrences within a file.
sed -i -e "s/$search_string/$replace_string/g" $filePath
I keep getting sed: unmatched '/'error on ...
0
votes
2
answers
81
views
Find and replace date with UTC date
I have file that looks like this:
[2024-01-20 15:23:00] hello world
[2024-01-20 15:42:00] bye
[2024-01-20 15:43:00] foo bar
...
Date in this file are in UTC+1 and I want to convert in to UTC
I tried ...
0
votes
1
answer
47
views
How do I tell sed to stop trying to process commands?
Maybe I'm an idiot (this is the likely scenario, and I'm new to sed/bash scripting), but why does this work:
NewVersion="$(echo $NewVersionFile | sed 's/^.*-\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/')&...
0
votes
1
answer
531
views
Moving files to a directory with spaces in its name
I'm trying to create a directory that has in its name the beginning of the names of the files it contains. I need this in order to archive it later. I have run into problems when moving files if the ...
0
votes
2
answers
1k
views
Find and replace string in a file using 'sed' or 'awk'
Let's say I have the following input file:
yhara.runner.mng1.nna1.X9HCJG.1 yhara.runner.mng1.nna1.Z2HCJG.1 100.000 100
yhara.runner.mng1.nna1.X9HCJG.1 yhara.runner.mng1.nna1.AUEM0K.1 94.144 72
...
0
votes
0
answers
108
views
How do I perform this sed command with bash?
I have a file full of usernames and I want to use sed to change the usernames to PLAYER 1-20 how can I do this with a bash script and sed while incrementing?
I have this so far:
NAME=$(grep -q 'Seat' $...
-1
votes
1
answer
165
views
write a efficient for loop in bash for multiple files (.PDB files)
I have problem with this script:
#!/bin/bash
for filename in /home/hb/pg/ensemble/pdbs/P24941/raw_pdb/*.pdb; do
grep COMPND $filename | grep "CHAIN:" -B 1 | sed 's/COMPND//g' | sed 's/...
1
vote
0
answers
340
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&...
0
votes
2
answers
583
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 ...
1
vote
2
answers
561
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
51
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
968
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
803
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-...
0
votes
1
answer
2k
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
186
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/...
-1
votes
1
answer
131
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,[email protected]
name2,lastname2,[email protected]
i need to delete the '[email protected]' in every line
essentially i want to make sed do "delete ...
2
votes
1
answer
376
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|/$...
1
vote
3
answers
7k
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
419
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" ...
2
votes
0
answers
898
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
3
answers
214
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
12k
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 ...
0
votes
1
answer
431
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
175
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
57
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
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
160
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
1k
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
286
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
2
answers
634
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\...
-1
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 ...
6
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
80
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 ...
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 ...
0
votes
1
answer
566
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 ...
1
vote
1
answer
1k
views
Replacing a string when it is not followed by string with Sed
I am looking for a sed script to replace a string when it is not followed by a string in the content of a file.
Currently I am at this approach
sed -i -E "s/${filehash}(?!.de)/${filehash}.de/g&...
0
votes
2
answers
84
views
Grep Sed with bash
I'm trying to achieve the following using bash and sed where the file containing below strings
qa2.test.m.xyz.com
554
1723
21
qa88.test.nj.xyz.com
1723
554
21
443
80
qa2.lite.xyz.com
554
1723
21
...
1
vote
1
answer
1k
views
Remove double quotes embracing variable strings from terminal
I have several files that contain this kind of line:
from="$variable_name" and other stuff
$variable name can change, so I could have
from="$myArray" and other stuff
from="$...
0
votes
1
answer
50
views
How to append a carriage return to replacement text in osx bash script
I've tried numerous answers that I searched for here, and for some reason nothing is working
I have a bash script which I'd like to use to process a series of files.
Here's a simplified example
a sql ...
0
votes
1
answer
143
views
Change the file content with bash
I have a question regarding manipulating a file content using bash. So I have a conf file has the content as below:
#set_var EASYRSA_REQ_COUNTRY "US" ...
1
vote
1
answer
1k
views
Use sed/awk to add specific text from one file to beginning of another file
I'm trying to use sed/awk to copy a range of text from the beginning of file1 to a specific line. Then add that output to the beginning of file 2 for a script I'm writing.
The following command does ...
0
votes
3
answers
2k
views
awk Removing Double Quotes from CSV File Quoted Strings separated by comma
I have a csv file I would like to remove any rouge " or , in it. The problem is all my fields look something like this "***********","*********", where * = can be any ...
4
votes
1
answer
684
views
Subshell won't work as indented
I have some files like this:
├── abc.conf
├── def.conf
├── xyz.conf
├── 10-abc.conf.postix
├── 10-def.conf.postix
and I want to remove the .postfix from all files which starts with 10-.
To do this ...
0
votes
1
answer
49
views
Using wildcards to do mass copying to slightly different names
I want to copy many files inside a single directory. An example filename starts with error042021.mysite and I want the new name end with -dev.co.at.txt. I think I need a wildcard for the number, ...
0
votes
3
answers
67
views
Can matched patterns be used in a replacement string?
I am new to both regular expressions and GNU sed. I have an anonymised sample of the data below.
RED: 13905 16356 17457 18164 18447 21063 26924 27684 30111 30205
CERISE: 6221 6524 18250 24367 24462 ...
0
votes
1
answer
716
views
Sed special characters in variable '&'
Sorry, easy question, but I can't find how to do it: I have a special char "&" in a Variables that I have to use in sed.
Example:
#The template .env
cat .env
MY_SECRET = VAR_MY_SECRET
...