Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [sed]

sed is a command-line stream editor for filtering and transforming text.

1
vote
2answers
18 views

Remove all matches containing a string until its next space

I want to delete all matches in a text following this pattern: Each match starts with linux- Each match ends with a space (Remove linux-* until immediate next space) EXAMPLE: From this text: ...
1
vote
1answer
71 views

Repeat print of a pattern repeated n times in one line with sed

With a sed cmd I want to print all occurrences of a pattern in one line. I know how to do this with grep -Pe and with awk. I started with: $ sed 's/^.*label="\(.*\)" selected.*$/\1/g' <(echo '...
0
votes
0answers
16 views

convert my csv file output to html table with heading bold and and send email using post fix & also want to change the font to calibri

for i in $(cat HPE_FRAMES_IP); do ssh Reports@$i showsys | awk '{print $2","$5}' ; ssh Reports@$i showpd -degraded -failed | awk '{print $1","$2","$3","$5}' ; done | grep -v "MiB" | grep -v "total" | ...
-1
votes
2answers
47 views

filtering output

for i in $(cat HPE_FRAMES_IP); do ssh Reports@$i showsys | awk '{print $2,$5}' | column -t ; ssh Reports@$i showpd -degraded -failed | awk '{print $1,$2,$3,$5}' ; done | grep -v "MiB" | grep -v "...
4
votes
3answers
257 views

Extract substring according to regexp with sed or grep

In a (BSD) UNIX environment, I would like to capture a specific substring using a regular expression. Assume that the dmesg command output would include the following line: pass2: <Marvell ...
0
votes
1answer
33 views

bash script to replace script tags in html with their content

is it possible to use sed to match the source of a script tag within html (which is not valid xml) and replace the whole match with the files' contents? e.g. say the html contained <link rel='...
1
vote
0answers
53 views

sed command is replacing the replaced text?

I am writing a bash script to rename icons. Specifically I am trying to change "icon-close-m" to "icon-close icon-size-medium" in HTML files. (though it could contain any substring besides "close", as ...
-1
votes
0answers
40 views

What is the “fsed” command used for? [closed]

I have to execute a script locally on my Laptop which runs a Fedora 29. The script contains several references to the fsed command: fsed 's/get.drivers//' ../scripts/hudson/launch.sh However I ...
0
votes
1answer
23 views

How to extract the URL from xml or any text file

My XML file; <settings version="2"> <setting id="TimeShift" default="true">0</setting> <setting id="Override" default="true">false</setting> <setting id="...
5
votes
2answers
148 views

Why is `sed` no op much faster than `awk` in this case

I am trying to understand some performance issues related to sed and awk, and I did the following experiment, $ seq 100000 > test $ yes 'NR==100001{print}' | head -n 5000 > test.awk $ yes '...
0
votes
1answer
26 views

How to extract the first column in a file with multi-character delimeter?

I have a file in which I use a string like <xxxxx> to separate the fields. This was a choice to avoid problems with the comma separated fields and other types of single characters due to the ...
3
votes
4answers
161 views

Replace four times with sed

I want to replace the second, third, fourth and fifth dots in this string 2019-03-17T11:32:28.143343Z;1234.5678;901.234;567.89012;3456.78;192.168.0.1 with a commas, to get this result: 2019-03-...
1
vote
2answers
49 views

Compare every nth line in 2 files and save (asymmetric) context

I have 2 files, each containing the same amount of 4-lines records, in the same order: fileA: record1 line1=header record1 line2 X <= this is different but should be ignored record1 line3 id ABC ...
0
votes
2answers
43 views

Change value inside xml attribute using sed?

I have the following attribute: <client-version>1.2.8</client-version> How can I replace everything inside <client-version></client-version> to only change the value (1.2.8)? ...
0
votes
1answer
42 views

Linux Shell - How to remove escape characters generated by JQ when json is read with sed?

I am trying to read a json file and use its output in jq to build another json, combining so said json file and other values, and pass it to CURL I read the file with policies=$( sed 's/\\//g' ...
0
votes
1answer
26 views

How to search and replace with sed in a line with variable content in it?

I tried to use sed to edit some part of a specific line in a text file and save the change to the original file. OK I now understand that this is not the way sed directly works. But how can I use sed ...
0
votes
2answers
62 views

Echo Results of a Variable in Sed Replacement

I have a file called LoginExcInternal.txt which has data that looks like the following: Name1 OpenFin/111.111.111.111 Name2 OpenFin/111.111.111.112 Name3 Chrome/111.111.111.111 These two ...
2
votes
2answers
160 views

Bash replace string at multiple places in a file from command line

I have a file with the below content. I want to replace chrome with chromeBackup but not in all places. Name=chrome XXXXXXXXXXX Run=bin -app "chrome/chrome.sh" XXXXXXXXXXX Vol.apps/chrome=chrome ...
0
votes
0answers
24 views

escape certain characters in a shell variable [duplicate]

I have a shell variable which will be used within the replacement string of a sed regex. Therefore, all characters &, / and \ need to be escaped by a preceeding \. I managed to do it for & ...
0
votes
1answer
29 views

How to append line with strings at the end of variable?

We have the following line in file more file USA_FORMAT="-XX:LOP83746=5M -XX:+YU3635-2837" and we want to append the following strings (line) also at the end of USA_FORMAT variable /usr/jdk64/...
0
votes
3answers
29 views

sed search and show matching pattern, removing the rest

I am trying to clean a list containing packages. I wish to remove the package revisions, leaving the package names only. I see every package has naming convention like this: package-name-majorver-...
0
votes
1answer
25 views

How to use sed to replace patterns with dynamic content may contains single/double quotes?

I'm trying to dynamically generate table of content for my markdown files, and trying to add it into the start of my markdown files. But the dynamically generated TOC may contains some single quote ...
0
votes
1answer
24 views

Text file: find string, save string field to var, find 2nd string, replace field with var, repeat to end

I think this would best be done with AWK, but not sure. Its been stumping me all day how to do this. I have a text file with * delimiters between the fields on the lines. I need to search for lines ...
1
vote
3answers
52 views

Sed add newline before last occurrence of brace?

I want to insert a new line before the last occurrence of brace. My text file looks like that "accounts": { "0x0000000000000000000000000000000000000008": { "builtin": { "name": "...
1
vote
4answers
42 views

Get a specific words from a specific line from a text file in NetBSD

How does one proceed to extract member names from a list like the one below and output them to a new file? Group-name supernatural Members admin, Admin1, John, sam, dean Group-id 405 expected out-...
0
votes
2answers
39 views

Remove data in between 2 words

I want to remove all data no matter what it is in between 2 words. The two words are user and Gecko) , exactly as it appears. For example: abcd: efgh user jfslkdj ajskdlfj askldjf Gecko) print ijkl:...
0
votes
2answers
95 views

Replace block of text with sed, awk, perl or vim

I am trying to replace every instance of a block of six rows with another block of six rows, just reducing the six rows block of two columns to a six rows block of only one column. Thank you to your ...
-1
votes
1answer
60 views

“unterminated `s' command” when doing substitution with sed [closed]

I'm trying to run the following sed command: sed 's?^?'`pwd`'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt > voc.2012.test But it is responding with an error message: sed: -e expression #...
1
vote
1answer
31 views

Using sed to replace a string containing any characters in a specific position

I have a file nginx.conf as below load_module /usr/lib/nginx/modules/ngx_stream_module.so; worker_processes 1; events { worker_connections 1024; } stream { upstream redis { server 34.73....
0
votes
2answers
52 views

Can't replace my regex matches

I can filter files, I can can stream the matches of my regex ... However, I need to remove exactly that, from a large file. Regex:^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$ sed ...
1
vote
3answers
63 views

Print SSH loop output Column wise

I want to print output of below loop into columns, Can anybody please adivse me on this. #!/bin/bash DATE=`date "+%d-%m-%Y_%H-%M-%S"` ### Find User from Server with Expiry Date for i in `cat /home/...
1
vote
3answers
54 views

Extracting text from a file when I know its format

I am running a script which will output a file called scServer.scs which looks something like this: 49138@bber0501u29b.bb2.cluster 2 Solution 1 Fluid Flow (Fluent) Solution ...
0
votes
1answer
35 views

Data extraction manipulation using awk [duplicate]

I have a snort.rule file, I need to extract cve numbers followed by reference key from the line and append them back in msg field of the same line inside flower brackets, below is the old log. ...
0
votes
0answers
23 views

Use variable inside sed command [duplicate]

how can i use variables inside this sed command? sed -i.bak -e '/triggerword/,${w $DIR/tempfile' -e 'd;}' $DIR/targetfile inside -e '{w $DIR/tempfile' -e 'd;}' the $DIR/tempfile isn't recognized
-1
votes
3answers
51 views

Comparing two files and show the content

I have two files containing content like the following: File 1 OG5_126568 OG5_126583 OG5_126593 OG5_126596 OG5_126599 OG5_126609 File2 OG5_126568 psychrobacter_aquaticus.txt WP_021813339.1 ...
3
votes
1answer
217 views

is 'sed' thread safe

If I have a shell/python script that uses sed to modify a file in place based on user inputs, and then two users run the same script at the same time or approx. same time, is 'sed' thread safe ? Or ...
0
votes
1answer
44 views

Log file extract data and append back same line

I have a snort.rule file, I need to extract cve numbers followed by reference key from the line and append them back in msg field of the same line inside flower brackets, below is the old log. ...
3
votes
4answers
241 views

How to remove trailing forward slash

For each line in my file, if the line ends with / I want to remove it. How to do this? My attempt: sed -e "s/$\/$//" myfile.txt > myfile_noslash.txt Did not work.
3
votes
3answers
319 views

insert EOF statement before the last line of file

I want to insert this cat <<EOF >> /etc/security/limits.conf * soft nproc 65535 * hard nproc 65535 * soft nofile 65535 * hard ...
2
votes
5answers
130 views

Removing c-style comments with sed

I need to delete some kind of characteristic, single line C++ comments from all files in our repository. Code looks something like this: some_code // characteristic_comment_to_delete some_more_code //...
2
votes
4answers
85 views

Removing (possibly nested) text quotes in command line

I need to parse large amounts text in command line and replace all (possibly nested) text quotes with spaces. Quotes are marked with specific syntax: [quote=username]quoted text[/quote]. Example ...
-1
votes
2answers
42 views

Looping by replacing the values in a file and then doing curl request for 25 times increasing count by 1000

I have a scenario of doing a curl request with payload from a file to my server. Here I need to replace values in my file incrementing values by 1000 and repeating the same for 25 times. I am able to ...
2
votes
4answers
313 views

How to count the characters of jar files by wc

Under the folder /usr/hdp/2.6.4.0-91/tez_hive2/lib/ We have .jar files as the following $ ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar" async-http-client-1.8.16.jar azure-data-lake-store-sdk-...
1
vote
5answers
47 views

remove all lines with nullbytes/corrupt data

So I recovered a text file from an old hdd, but I failed to completely recover all of the data. The data that wasn't correctly recovered has returned as null bytes. How can I remove every line from ...
0
votes
1answer
31 views

replace character if repeated in line below

I have the following sequence, N H CB CB CG1 CG2 C O N H CB CB CG CD . . . and I would like to replace the first "CB" with "CA" when "CB" is repeated in line below, so as to end up with the ...
0
votes
1answer
29 views

sed: insert text after specific character in a specific line

Below is my text file: example.txt INTERFACESv4="" INTERFACESv6="" Below is my code (it inserts an IP address after the 14th character): ip_add="192.168.1.2" file_name="$HOME\Documents\example.txt" ...
2
votes
5answers
137 views

Sed or awk - Insert a new line after Matching pattern

I have a file which contains multiple URLs. But unfortunately, all the URLs are in one line. cat url_file http://transfer.sh/PIGfk/my-file.002554http://transfer.sh/Ep9Md/my-file.002555http://...
1
vote
1answer
254 views

sed not parsing \t as a tab

I am trying to insert a line into a coffee script using sed and it looks as if it is ignoring my first tab character. The file I want to insert into has a line like this: karmaServer.start and ...
-1
votes
2answers
39 views

Extract lines from a file with a value,whose parameter greater than 100, with grep and awk [closed]

I have a file, and I have to create a script with the following output file as per the specifications: The input file has first 28 lines of header, which have to be included in the output Some of the ...
0
votes
3answers
52 views

How to insert a line into a crontab AFTER a key word or string via script

I understand there is a lot of documentation on editing crontabs via script, and I can do this by adding an entry with the following command: line="* * * * * /my/folder/script.sh" ( crontab -l ; echo ...