Questions tagged [sed]
sed is a command line editor for POSIX environments. It processes one or more files according to an editing script and writes the results to standard output. Created at Bell Labs, it has been around since the mid-70s.
28,685
questions
-1
votes
2
answers
63
views
sed or perl replacing sub string only, with the result of other command
How, by one-liner sed or perl, to replace a sub string only, with the result of other command execution, in the middle of full line string e.g:
$ cat f
iiiiiii
OOO=dd=XXX
uuuuuuu
it's clear in string ...
0
votes
1
answer
25
views
sed to rebuild a manifest from a 2nd file
I'd like to replace a file content for some lines (not all of them) matching another file content:
File1 is a manifest with this format (thousands of lines):
...
f 755 myself mygroup /opt/app/...
0
votes
3
answers
77
views
Linux CPU string by Bash
I try to build a string that identifies my CPU.
cat /proc/cpuinfo | grep "model name"
model name : Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
model name : Intel(R) Core(TM) i7-6700HQ CPU @...
0
votes
2
answers
35
views
Using sed to edit complex ids from large text file
I want to change the IDs in this large text file so that only the second field in between the ';' stays. See below:
Go from this:
> AT1G01030;AT1G01030.2;atRTD2::1:11648-13714
> ...
0
votes
4
answers
69
views
Sed command can't find value with underscore
I'm trying to change values in yaml file using sed command (can't use yq).
I have a file test.yaml with following:
app1:
value1: 0
value2: 7
value_3: 5
app2:
value1: 1
value2: ...
0
votes
0
answers
29
views
GNU sed to BSD sed for bash goto function
I make extensive use of a bash goto function that works through a GNU sed command. However, the sed command is not compatible with BSD sed. How would I need to change it to function correctly in an ...
-2
votes
1
answer
48
views
How to get a specific number from a list of items using awk or sed in linux [closed]
1 = ["vm1", "product-sample-1", "130", "small_size","ENV"]
2 = ["vm2", "product-sample-2", "145", "large_size&...
2
votes
2
answers
30
views
How to fix hyphen for sed using hd -c
I have a file (c.txt) with the following output. This is only one item in a large file.
7,VE,Bank–Charges
I am trying to run:
sed -i 's/-/ - /g' c.txt
to get the desired output of:
7,VE,Bank – ...
-5
votes
0
answers
46
views
Linux 'sed' regular expression [duplicate]
I have this piece of XML repeated many times in a very large file:
<A>999</A>
<B>
<C>999</C>
<A>999</A>
<C>999</C>
<A>999<...
0
votes
3
answers
78
views
sed - how to replace yaml.j2 nested value
I have a command that I use to replace myid value but its not perfect. Here is document where the issue occurs:
brand:
group1:
jerry:
myid: 1
ben:
myid: 2
...
0
votes
3
answers
52
views
Sed command to replace "(double quote) to " and ' (single quote) to ' in all xml tag value in a file
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<InnerDoc>
<GrpHdr>
<MsgId>aaa.xml</MsgId>
<CreDtTm>...
-3
votes
2
answers
41
views
Ansible lineinfile to add a string in front of every line and convert to single line [closed]
I am using sed to add a string in front of line and then xargs to keep in single line. How can I achieve same in ansible ?
For eg :
I have a file as below
[root@test]# cat tt
aa
bb
cc
dd
With sed ,
...
0
votes
0
answers
50
views
Helm upgrade not picking up changes to values done by sed command
I have an Azure Release pipeline that simply deploys a helm chart of a microservice to a k8s cluster. I'm trying to modify values of requests and limits by pattern matching using sed command. I've ...
0
votes
4
answers
243
views
More than 6 characters string repeated
I am trying to find the repeated strings (not words) from text.
x = 'This is a sample text and this is lowercase text that is repeated.'
In this example, the string ' text ' should not return because ...
1
vote
3
answers
79
views
Replace /" from the 14th column of the file in unix shell script ksh
I have one file which has 10000+ records. There are some bad records which has /" in between the value like below. This is comma delimeter file. I cannot use -E GNU option.
"22-11-2020",...
-4
votes
4
answers
78
views
How to remove all versions from requirement file with bash "sed" [closed]
The following python requirement file defined more than 500 packages, and each package has a " == " and then the version string.
# comment string
python_package_a == 1.2.3
# some text
...
0
votes
2
answers
74
views
sed bash regex without look arounds [closed]
I have a file called test that contains the following:
foo
bar
baz
foo or bar
foo or baz
bar or baz
And a single comma is desired at the start of each line. How can I match any of these phrases ...
-4
votes
2
answers
85
views
apply sed only to the part of the file after last match in loop - shell / bash [closed]
I have a couple of large files (~1Gb) of such structure:
fooA iug9wa
fooA lauie
fooA nwgoieb
fooB wilgb
fooB rqgebepu
fooB ifbqeiu
...
fooN ibfiygb
fooN yvsiy
fooN aeviu
I would like to replace in ...
0
votes
3
answers
64
views
how to insert dots (.) in a string in bash scrip with sed or awk , 100000000 >> 100.000.000 [duplicate]
I am writing a script that gives me a figure in millions 123456789 and I want to add the points to the numerical string like 123,456,789
:~$ a=100000000
:~$ b=100000000
:~$ c=100000000
:~$ tvusd=$(...
3
votes
3
answers
102
views
Removing first and last double quote (preferably sed/awk)
I only want to remove the first and last double quote
input:
word1 -word2 {word3} -word4 {"word5 'word6' "word7 word8" .word9"} -word10 (word11)
word1 -word2 {word3} -word4 {"...
-3
votes
1
answer
90
views
Extract N lines with no duplicate strings from either of the two first columns
I have a huge CSV file with pairs of unique combinations. I need to extract N random lines of this file, but I need that the strings in col 1&2 to be unique, so that the list of unique strings in ...
-5
votes
4
answers
87
views
How should I go about implementing conditional string replacements in a fasta file?
I have a large fasta files with various bacterial species names in each of the sequence headers that looks something like this:
file.fasta
>Bacteria;Actinobacteria;Actinobacteria;Streptomyces;...
3
votes
5
answers
91
views
"Greedy" search & replace for sed
I have a bash function to get a prefix from a string up to and including the character "-".
get_prefix_with_hyphen() {
# get prefix with trailing hyphen
prefix_with_hyphen=$(echo "$...
1
vote
2
answers
92
views
SED: Strange behavior in sh and bash, ok in zsh
I have a strange behavior with a sed command.
First, my concern is to have a sed command in a Bash script that enables me to replace a string located after the string sas_token.
Here is the file:
...
1
vote
3
answers
68
views
how does this command execute: sed -n 'N ; s/#\n@/#--@/ ; P ; D' corruptData.txt
I don't know why the sed command make the output as bellow:
shell command : sed -n 'N ; s/#\n@/#--@/ ; P ; D' corruptData.txt
output:
Header Line#--@#
@Data Line #1
Data Line #2#--@
End of Data Lines#-...
0
votes
4
answers
106
views
Find and return blocks of lines containing a string
I have a big file of the following type:
key = asbh
some
lines
of
**text**
key = kafeia
some
more
**text**
and
additionally
more
**text**
and
more
key = lklfh
this
is
another
block
Note (if ...
0
votes
4
answers
75
views
Extract Regex Capture Group in Script
I am writing a CSH script and attempting to extract text from a source string given a key.
!/bin/csh -f
set source = "Smurfs\n\tPapa\nStar Trek\n\tRenegades\n\tStar Wars\n\tThe Empire Strikes ...
-2
votes
0
answers
38
views
Trying to reverse contents of a file using sed '1!G;h;$!d' on MacOS. This returns zsh: event not found: G [duplicate]
I am trying to reverse contents of a file using sed '1!G;h;$!d' on MAC. However, I get the error zsh: event not found: G.
I am using gnu-sed installed using homebrew - installation done by following ...
1
vote
1
answer
58
views
Sed replace single text with content of file
I have a question regarding using sed.
I have a JSON file and I want to get it inserted in another file.
What I'm trying is to get all the contents of the .json file which contains 4500 lines, and ...
1
vote
4
answers
84
views
How to convert log to CSV format using sed function?
I have some log content in a file named as log1.log which I want converted to a CSV format file named as output1.csv. I have given the log file content as below:
35 - - [30/Apr/1998:22:00:17 +0000] &...
-1
votes
3
answers
73
views
Delete a tagged section of text plus the next line in a file using sed
If I have a file like this with variable length sections of text between tags.
--
-- <tag1>
-- some text
-- </tag1>
--
-- <tag2>
-- </tag2>
--
-- <tag3>
-- other stuff
-- ...
6
votes
5
answers
181
views
Trying to extract a substring and version number from a filename using bash
I'm currently trying to extract a substring and version number from a filename using bash.
There are two formats the filenames will be in:
example-substring-1.1.0.tgz
example-substring-1.1.0-branch-...
-2
votes
3
answers
72
views
Remove any returns/newlines between two strings
I am on the last step of my showtimes script that pulls my local theatres info and converts it to a clean text format. I have added some "flags" and I want to remove any returns that may ...
-2
votes
3
answers
57
views
How do I check if there are duplicate values across files at a specific position
I have about 2000 files in a directory on a Linux server. In each file, the positions x-y have invoice numbers. Which is the best way to check if there are duplicates across these files and print the ...
0
votes
2
answers
58
views
sed add dots between two or more capitals and capitals not followed by lower case letter
I need help with sed
Two commands
add dots between two or more capitals
capitals not followed by lower case letter.
I'm trying any two or more capitals to have dots between them.
I would like to ...
0
votes
1
answer
87
views
Replace carriage return (^M which appear by type CTRL+V) with sed in bash
I'm trying to manage a file .xlsx in bash with a format of csv.
I do convert the excell the file (.xlsx) to .csv (CSV UTF-8(comma delimited)) to start managing the columns.
However, i notice in the ...
0
votes
2
answers
39
views
Linux sed command to replace dynamic values
I'd like to replace several string in a file having a 'false' value with a 'true' value with a single 'sed' command.
My problem is that in the middle of the string there is a dynamic part like one,two,...
-1
votes
1
answer
58
views
Replacing Text With SED Using a Wildcard in the Input and The Output
I am trying to clean up some data, but I have an area where the date and times are running together. Below is any example of I would like to do, ideally. Of course, there are double digit dates but ...
3
votes
4
answers
115
views
How do i change a VIM sedcommand to work in a bash script?
I have a very useful sed command in Vim that I want to put in a simple bashs cript.
But I have tried many variation of it (googled like crazy) but it does not work...
The sed string that works in Vim ...
0
votes
0
answers
29
views
Use sed to replace multi line values [duplicate]
I have a file called input.bash, the file contains the following formatted var
VAR_1=`cat << EOF
[
{
"Property_1": "1",
"Properties": {}
}
]
...
-1
votes
0
answers
35
views
invalid command code m while executing sed [duplicate]
I have created a file called input.txt
company.user.url=tcp://localhost:8080
Now I want to replace through my actually url and therefore I am using the below command.
sed -i "s/company.user.url=...
-1
votes
0
answers
37
views
Unwanted newlines generated when using sed to replace values [duplicate]
I'm trying to automate replacing a bunch of IP addresses in a config file.
For that I created a separate file which contains the old IP and the new IP in pairs on a line, separated by a space like ...
0
votes
2
answers
83
views
Using git clean filter on windows, script does not make substitution
I'm trying to increment a value within a file when it gets staged. I'm using clean filter with:
*.txt filter=increv in .gitattributes
and the following in my .git/config
[filter "increv"]
...
-1
votes
1
answer
118
views
Perl Script: Neet to write a pattern based script to replace the values using perl
I have a test file which contains many urls. All i have to do is writing a pattern based perl script where ever i see values need to change as SSSS in the url (value=combination of upper case, lower ...
-6
votes
1
answer
100
views
extract rows from csv where first column value matches first column values in another file (bash/awk/sed) [closed]
I have two csv files:
#source.txt
"some_id","some_value","1"
"some_id2","some_value2","2"
"some_id3","some_value3","...
0
votes
3
answers
62
views
CamelCase only for some part of the line using shell tool
my goal is to have a one liner to generate a list of variables composed from the name of the variable and its value. The value must be kept "as-is" while the name of the variable must be ...
3
votes
4
answers
76
views
Remove commas between patterns
I am trying to replace all commas with a space between ";" and "[" in my text file using sed. An example line is: K01810,GPI,,pgi;,glucose-6-phosphate,isomerase,[EC:5.3.1.9] where ...
-3
votes
0
answers
50
views
How to extract fields from yum.log where it has fail or skip keyword
The below are the field description, and I need to extract the lines when it reaches failed / skipped and the next few lines.
Failed:
Python
Httpd
Php 3.2 **your text**
I want to extract ...
2
votes
2
answers
53
views
How to use awk to capture multiple patterns in text file into several blocks of text and print each block to a new file
I have this bind dns stats text file, sample_data.txt:
+++ Statistics Dump +++ (1698804161)
++ Incoming Requests ++
34199522 QUERY
2 STATUS
12 UPDATE
++...
2
votes
2
answers
42
views
SED pars two values from output file
I am having hard time try figure out how to pars two values from below output:
CHANNEL(SYSTEM.DEF.SVRCONN) CHLTYPE(SVRCONN)
ALTDATE(2022-11-06) ALTTIME(21.48.22)
...