Questions tagged [sed]

Sed is known as a Stream Editor in that it can carry out various filtering and/or transforming functions on standard input or on user specified files. It is commonly used to search-and-replace in text files. If your question is about text-processing, this tag is likely to be appropriate

Filter by
Sorted by
Tagged with
0 votes
2 answers
689 views

How to replace string with file contents which contains symbols using sed

I have one word in one of my files and I want to substitute that word with xml file contents. considering that xml file contains some symbols which sed isn't able to process the command I am using isn'...
Saba's user avatar
  • 113
2 votes
2 answers
3k views

Using sed to replace multi-line strings in apache2.conf file

As part of my Bash server setup script, I am trying to lock down the default apache www website. I want to convert this: <Directory /var/www> Options Indexes FollowSymLinks To this: <...
Andrew's user avatar
  • 33
0 votes
2 answers
150 views

Bash command to recognize difference between variables

I am given from stdin 2 variables a name and a number given in any order. How can I identify them correctly in a bash script such that I can print them in a file in the same order(age, Name) ./a.sh ...
satalmaty 's user avatar
5 votes
4 answers
33k views

How to set up DISPLAY variable for WSL2 of ubuntu 20?

I have a WSL2 with ubuntu 20. In most posts, setting up DISPLAY environmental variable to access windows X11 server is made through WSL localhost address in ~/.bashrc $ export DISPLAY=$(awk '/...
youssef's user avatar
  • 353
0 votes
4 answers
486 views

Awk/Sed commands find and replace pattern

I have a file with data like the following. xyz can be anything, so I want to replace it. variable "azure_spoke_gateways" { default = { spoke1 = { name = "xyz" ...
Shahroz Pervaz's user avatar
0 votes
1 answer
119 views

Sed insists on doing partial matches

Ok, consider this example file: #!/usr/bin/env bash cat > example_file.txt <<EOL group, , price 1, S_BRN_, 3.21 1, S_WBS_BRN_, 4.11 1, S_WBS_BRN, 1.22 2, S_BRN_WBS, 9.2 2, F_WBS_BRN_, 2.11 2, ...
user2413's user avatar
  • 14.4k
0 votes
1 answer
105 views

how to swap the time and cpu usage in shell script

This is my code here, ps -eo %cpu --sort=-%cpu |head|tail -n+2 | sed "s#^#$(date +%T);#" and the display will be like this: 01:29:29; 1.2 may I know if I want the output like: 1.2;01:29:29 ...
user1153111's user avatar
0 votes
2 answers
249 views

Remove LF from a specific column using sed

I have a file which contains data separated by |. Example: (Input) a|b|c|d`LF` D|e a1|b1|c1|d1`LF` d2|e1\n Output: (Removed LF from 4th column) a|b|c|dD|e a1|b1|c1|d1d2|e1\n I want to remove LF from ...
Rajat Garg's user avatar
0 votes
1 answer
56 views

Need to add " " on a target of different strings in a txt file

hope everyone is ok. Want to add " " on a txt file for example : 12 maker_ITAG gene 64046325 64049958 . + . gene_id Solyc12g057010.2 12 maker_ITAG mRNA 64046325 ...
Jim Hat's user avatar
  • 21
5 votes
3 answers
2k views

How to use sed to delete timestamp pattern from a zero-terminated list of filenames

To find files older than the newest 8 I'm using: find . -maxdepth 1 -type f -printf '%T@ %p\0' | sort -rz | sed -z 1,8d The -printf '%T@ %p\0' command applies a last modified timestamp (expressed as ...
Broadsworde's user avatar
  • 4,142
0 votes
2 answers
26 views

Wrap specific field on each line

file: DocumentNameA varying number of words symbols etc DocumentName2 varying number of words symbols etc AnotherDocumentName varying number of words symbols etc I want to do something like sed -i 's/...
Insideup's user avatar
  • 115
0 votes
1 answer
896 views

How to replace every 2nd line sed

How to replace every 2nd line of a text file with another text file list of lines. Example: cat filea.txt I love Pink I love Blue I love Dogs I love MOMO cat bileb.txt I hate yello I hate white I ...
Pooja Jha's user avatar
0 votes
2 answers
67 views

Commandline copy of contents between patterns from a text file to another

I have an html file contents copied to a text file in the following form: ... course 10> user_1 </a><br /><a class="reviewlink" href="https://www.foo.com/moodle/mod/...
Praveen's user avatar
  • 1,015
3 votes
2 answers
8k views

Convert HTML to text format

I want to extract the page content from this HTML file: <BR /> <TABLE style=border-color:#32506d border=1 cellspacing=0> <caption class=header style=background-color:#32506d><...
Srinivasulu Reddy's user avatar
0 votes
1 answer
113 views

How to replace a varying number of strings on lines that match patterns

File1 <filename1.txt> stringA string1 <filename2.txt> stringA string2 <filename2.txt> stringB string3 File2 <filename1.txt> words and symbols < $ stringA words and ...
Insideup's user avatar
  • 115
0 votes
1 answer
48 views

How to add interative value to each line of a file?

Numlines=$(grep "" -c file.txt) # This works for line in $( seq 1 $Numlines) # for each line do sed "s/$/ Line${i}/" file.txt # not right done file.txt: this is the first line ...
Insideup's user avatar
  • 115
0 votes
1 answer
466 views

Change the text according to match for each line

I have a text file which contains some text is shown below: I love bash $ I love html $ I hate you I love you man I want to add some text at the beginning and the end of the line with a match of $. ...
Pooja Jha's user avatar
0 votes
3 answers
2k views

Inserting text to existing text within brackets

I have a file similar to this: [one] [two] [three] [four = something] I want to add /mame/ in front of the word in square brackets except when there’s an = sign on the line So the above will be [/...
Scally's user avatar
  • 1
0 votes
2 answers
79 views

I need to make a shell script that displays config files without the commented and empty lines

This is my code: #!/bin/bash echo "Type in your file" read file sed -r -e 's/(^[^#]*$) ; s/(^[^;]*$) ; s/(^[^$]*$) ; s/(^[^/]*$) ; s/(^[^ ]*$)' $file This is the output when I give it a ...
Nico Nico Pizza's user avatar
1 vote
1 answer
114 views

replacing text between brackets from text in file

I have configured the server instance in code "instance": [ { "address": 127.0.0.1, "port": 6514 }, {"address": 127.0.0.1, "port": 6515 } ] ...
Avinash Baldi's user avatar
0 votes
1 answer
152 views

Removing multiple lines between brackets

I have the following "endPoints" : [ "127.0.0.1:8090/abskdj/index.html", "127.0.0.1:8091/qwe/we.html" ], (may contain one or more addresses) I want to change ...
Avinash Baldi's user avatar
0 votes
1 answer
181 views

Using sed to store multiple IDs within an array, that are on the same line of a file

I have several files that contains IDs that I need to extract and store into an array, problem is that all the IDs are on the same line and all follow the same patterns, also each file has a random ...
DamLk's user avatar
  • 1
0 votes
3 answers
2k views

Shell script to extract data from a file and store into another file as a csv

I have a set of .html files within a folder and I'm trying to look through each folder and extract a particular bit of info and store it into a CSV file. Each file contains a similar line of data: <...
DamLk's user avatar
  • 1
1 vote
1 answer
6k views

execute all files under a directory with sed and find

I'm trying to use find to execute all the files under a directory. I have a sed script that will replace all instances of # with //. Assume my directory is /path/to/directory and it contains file1, ...
bull's user avatar
  • 11
4 votes
3 answers
2k views

"sed" to add a space only under a certain condition

I have to add a space after the # to every occurrence, only if the # is at the beginning of the line and after the # there is at least one character that is not the space. For example this code: echo &...
Mario Palumbo's user avatar
0 votes
1 answer
754 views

How to insert N+1 new lines after each line of a file with sed

I want to change this: This is line1 This is line2 This is line3 To This is line1 InsertedLine This is line2 InsertedLine InsertedLine This is line3 InsertedLine InsertedLine InsertedLine I.e. new ...
Mark's user avatar
  • 1
0 votes
1 answer
382 views

sed with parens in seach not working

I need to replace DatabaseConnection.GetConnection() with DatabaseConnection.GetConnection(_connectionString) Using grep (GNU grep) 3.1 grep GetConnection() CustomerRepository.cs yields bash: syntax ...
user2443507's user avatar
1 vote
2 answers
169 views

How do I get `abc.xyz.com` from `"127.0.0.1,abc.xyz.com"`?

I have a list in which data is in this format "127.0.0.1,abc.xyz.com" I want to get only abc.xyz.com without the IP address and double qoutes. How it can be done?
DedSec's user avatar
  • 83
2 votes
2 answers
10k views

sed reports "unknown command"

I wrote this: sudo sed -i ‘s/3389/3390/g’ /etc/xrdp/xrdp.ini That produced this error: sed: -e expression #1, char 1: unknown command: `'
Arunabh Singh's user avatar
1 vote
1 answer
543 views

Sort order of output when using sed and iterating in folder

I am using the following sed command to find a string in between patters for each file in a folder, files are named 01.txt, 02.txt etc.: sed -n '/PAT1/,/PAT2/{/PAT1/!{/PAT2/!p}}' * >> file but ...
rearThing's user avatar
  • 169
1 vote
1 answer
120 views

How to make sed or by using another command to reprint a found string?

I have a string like: testfsdfsdftestfsdkflsdtestsdfsdfsdf I am wondering how to separate the string so that testfsdfsdf appears on the first line, testfsdkflsd will appear on the second line, etc. ...
user1046658's user avatar
1 vote
1 answer
4k views

How to search an XML file and print text of a certain color

I have tried grep, awk, sed and am starting to try xmlstarlet but I'm not finding much support with that. I'm guessing the xmlstarlet is telling me that the XML is ill formed, but all I want to do is ...
Insideup's user avatar
  • 115
0 votes
1 answer
4k views

How to use sed to remove variables value from a string [duplicate]

I am writing a script in bash and I can remove a string from a sentence using the code below: echo 'This is a foo test' | sed 's/\<foo\>//g' OUTPUT: 'This is a test' However, I want to be able ...
Ashim's user avatar
  • 153
0 votes
1 answer
1k views

Insert a line after match using sed

I want to insert a new line after this line: set_config_object("m_lin_1_pad_agent*","io_agent_config",m_lin_1_pad_agent_cfg,0); Can you please guide me on how I can achieve that ...
Tejas Kulkarni's user avatar
0 votes
1 answer
136 views

Trimming variable text from string lines

I'm trying to trim strings in a large text document. They all begin with >chr5: and then a variable string of numbers. For example: >chr5:1264398-1264827. I want to trim these all down to just ...
Logan George's user avatar
1 vote
1 answer
188 views

Get human readable cpu frequency

I am trying to get a simplified output of the cpu frequency to 3 digits, such that if the frequency is less than 1000 it will output xxx Mhz and if it's above 1000 it will outpute x.xx Ghz. I can get ...
James Palmer's user avatar
0 votes
0 answers
4k views

ubuntu/bash sed: operation not permitted and permission denied

I'm using Windows 10 with WSL2 feature turned on, and working on Ubuntu. All the files I'm working with are saved in Windows and not the Ubuntu subsystem, so I've been accessing Windows directories (/...
Jen's user avatar
  • 101
0 votes
1 answer
293 views

With sed what is difference between sed -n '1,2p;3q' and sed -n '1,2p;2q'

Is there any difference between sed -n '1,2p;3q' and sed -n '1,2p;2q' I have a file with 3 lines: #comment 1 #comment 2 #comment 3 And I couldn't notice any difference. Both printed out the first ...
An Ignorant Wanderer's user avatar
1 vote
1 answer
1k views

Trying to add an ampersand at the end of every line of file using sed

I am trying to add an ampersand at the end of every line of a file using sed as follows: sed -i -e 's/$/ &/' file However, when I look at the contents of the file (using both Vim and just cating ...
An Ignorant Wanderer's user avatar
1 vote
1 answer
1k views

'column: line too long' when it doesn't seem to

I'm using grep, sed and column to make a little makefile documentation, but I get the following error: column: line too long. My attempt is the following: ## this is the documentation yes: @echo ...
Clément Jean's user avatar
3 votes
1 answer
1k views

Edit FASTA header

I want to remove part of the header of all my sequences in a fasta file, so only the Otu number appears as the header. So from: >M02300_51_000000000-CJMTC_1_1115_17014_15334 Otu0001 T-AC--GG-AG-...
katherine HM's user avatar
0 votes
2 answers
507 views

Keep original spacing while doing replacements [AWK, SED, GREP, ...]

I have two files which content are: File 1: ATOM 1 N LEU 1 -10.186 -21.276 -0.497 1.00 0.00 PROT ATOM 2 HT1 LEU 1 -10.773 -22.005 -0.843 1.00 0.00 PROT ...
Another.Chemist's user avatar
3 votes
2 answers
2k views

Rename multiple files with variable extensions to remove beginning and end of filename

I have multiple files I need to rename as below: 5891_1_0_AD3884_ACTCTCGA_S10.bam 5891_1_0_AD3884_ACTCTCGA_S10.bam.bai 5891_1_AD3875_GAGCTTGT_S1.bam 5891_1_AD3875_GAGCTTGT_S1.bam.bai ...
csijcs's user avatar
  • 33
0 votes
0 answers
237 views

SED command runs from console but not through incrontab

Trying to make find and replace in a file when it is modified by the system or other user. Incron+SED is the combination has worked the best till this moment. Problem is when the command is put into ...
Lauris Kārkliņš's user avatar
0 votes
2 answers
4k views

How to append text in the beginning of each line using sed

<AppendNhere> A H W C <AppendNhere> A H W C <AppendNhere> A H W C Sed '/^/ i N' filename I tried appending N using this, but it's appending N to the beginning of new ...
Andy's user avatar
  • 1
0 votes
3 answers
864 views

Removing characters (digits) after the first dash (-) from the end of a fileName

I have thousands of .mp3 files that have recently been required and were appended with a dash - and a series of various amounts of numbers. I would like to remove the last dash and the numbers to ...
rod-a's user avatar
  • 1
1 vote
1 answer
3k views

Find index.html files & Rename with folder name and move file a level up

Little help in solving a workflow with shell script using the find command. Finding all index.html files in every folder. We can use this with find command for that. find ./ -type f -name 'index....
Suresh Kumar Gondi's user avatar
0 votes
1 answer
65 views

Change regex's result order after sed as order of ls -v

I am working on 53 xml files (az-0.xml ~ az-52.xml). And I ransed '/<loc>/!d; s/[[:space:]]*<loc>\(.*\)<\/loc>/\1/' az-*.xml > AZ to get all stuff in <loc> and merge them ...
yan chen's user avatar
0 votes
0 answers
228 views

Using sed to find a word and replace another word

I have a word like <string>any word</string> in a file. I want to replace it with <string>17E262</string> For example: I want to convert <string>16G183</string>...
mật khẩu không đổi's user avatar
2 votes
2 answers
277 views

Remove word and character from strings

Is there a method to remove this string "name": "_acme-challenge", and left only with : _acme-challenge I read that I can use sed but I don't understand much how to go with this.
Kalib Zen's user avatar
  • 155

1 2
3
4 5
15