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
-1
votes
2answers
38 views

How to use sed to delete file extensions from list of filenames

I have a bunch of .txt files in a directory, and I want to be able to find these files and strip the extension from the file name. I can find the files using: $ find . -maxdepth 1 -type f -name "*...
0
votes
1answer
42 views

Weird output while using sed to rename files

I am using Ubuntu 20.04.2 with GNU sed version 4.7. I have a bunch of music files that got named weirdly because they did not have all the info I specified to be in the file name. For example, "...
0
votes
1answer
39 views

find: paths must precede expression: `.'find: possible unquoted pattern after predicate `-exec'?

i need to execute in background this command sudo find '/abc/abc/' -type f -exec sed 's/domain1\it/domain2\com/g' '{}' \; . & but I have two issues: find: paths must precede expression: `.' find: ...
1
vote
3answers
55 views

Batch Rename DIrectory Using Pattern Matches

I would like to change this directory structure to the one following it. Although another directory batch rename question exists, this one is quite different. l '001. Aretha Franklin - Respect.mp3'* '...
0
votes
0answers
52 views

How to fix problem with half outputs results

for f in 20*.txt do sed -n '1p' "$f" | cut -d' ' -f3 >> displayStudentInfo.txt head -3 "$f" | tail -2 >> displayStudentInfo.txt done cat ...
1
vote
2answers
43 views

Backslash missing in file while replace the string content using backslash contain variable

I want to write backslashes in a file, and I try to substitute some text with the value from a variable: $ TEST=\\etc\\hello $ echo $TEST \etc\hello But the backslash is missing when I tying to ...
1
vote
1answer
57 views

how to use grep and sed on adb logcat

I'm currently using grep in combination with adb logcat (android console api). Now I want to edit every line on the fly using sed in a pipe. However when using sed after grep the output becomes empty. ...
0
votes
0answers
58 views

How to remove part of of line with sed

I have a line that I want to remove: "}},"has_video":0}" I have used this to remove most of what I needed to remove: sed -i 's/",.*(n)\.(n)//'
0
votes
0answers
31 views

Caching the last 3 values of a variable isn't working inside script

My goal is to cache the value of a variable, going three times into history. So: path=value3 cache1=value3 cache2=value2 cache3=value1 ---------------- path=value4 cache1=value4 cache2=value3 ...
1
vote
2answers
49 views

Append multiple digits to the end of eatch lines

i need to cat temperature values in /sys/class/hwmon/hwmon[0-9]/temp[0-9]_input and append them to the corresponds names in given file. help !
0
votes
1answer
38 views

sed edit string between spefic paragraph in a file

I hava a file called a.txt. And it contains the following contents. It's unknow how many lines between each function. function a( line 1; line 2; line ...; properties pro = "test"; ) ...
2
votes
1answer
142 views

Sed command not working as expected

I am using Ubuntu over WSL. It looks like sed is not working as intended. It doesn't replace the text if the search text in more than one character. When I execute the following command sed 's/l/XYZ/...
0
votes
1answer
55 views

How to “timeout” a function so that it only runs once every 5 seconds eventhough it is called multiple times per second

See below: still_notify=false has_been_notified=false notify() { $has_been_notified && return watching=$(if [[ $(GET http://$ipplexserver:32400/status/sessions?X-Plex-Token=$...
0
votes
3answers
73 views

how to split a string from a column using awk

I am a noob in Linux. I have a file like this: col1 col2 col3 ID1234567-DNA_A01 chr1_10203040_T/C gene 0 ID1234568-DNA_A02 chr1_10203050_T/A gene 0 ...
0
votes
1answer
16 views

linux command sed only show line 1 to 2 not work

I use sed to show the first 2 lines of the file 'sed.txt',but it does not work: the file sed.txt is like: $cat sed.txt 1 2 3 4 use sed command: $sed -e '1,2p' sed.txt 1 1 2 2 3 4 the line 3 and 4 is ...
0
votes
1answer
27 views

How to replace text from a match (but not every match)?

I want to replace AllowOverride None from the group that has /var/www/ path. I'm using sed to do this but it's replacing every match. apache2.conf before running the script <Directory /> ...
0
votes
0answers
49 views

sed - trouble using a variable which is previously set with another variable

I would like to know why sed does not work when the value is set in var, $thecolor ? (I cannot use an HTML parser for this). The desired result is available without using a variable to set $...
0
votes
0answers
73 views

Changing variables (outside of while-do loop) with sed (inside while-do loop)

I have a question. See the following: path="/library/metadata/2695/children" location="http://192.168.2.15:32400$path?X-Plex-Token=[[plex token]]" option="4" Inside ...
0
votes
1answer
59 views

How to replace terminal title using sed in PS1 prompt string

I've been at it for > 1 hr. and can't figure this out. Here's my PS1 prompt string: $ echo $PS1 \$SHLVL:2 \e[7m$(gs_git_show_branch)\e[m\n\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\...
2
votes
1answer
120 views

Bash script to update BIND ACL - unwanted character

I am trying to update a file on a server where the new line needs to have a single tab at the front but new to bash scripting and sed and keep getting an unwanted character at the front. This is the ...
0
votes
2answers
101 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'...
1
vote
2answers
132 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: <...
0
votes
2answers
56 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 ...
0
votes
4answers
160 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" ...
0
votes
1answer
20 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, ...
0
votes
1answer
61 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 ...
0
votes
2answers
54 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 ...
0
votes
1answer
48 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 ...
6
votes
3answers
526 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 ...
0
votes
2answers
19 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/...
0
votes
1answer
58 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 ...
0
votes
2answers
40 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/...
1
vote
1answer
793 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><...
0
votes
1answer
81 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 ...
0
votes
1answer
40 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 ...
0
votes
1answer
56 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 $. ...
0
votes
2answers
68 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 [/...
0
votes
2answers
59 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 ...
1
vote
1answer
50 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 } ] ...
0
votes
1answer
49 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 ...
0
votes
1answer
33 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 ...
0
votes
3answers
770 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: <...
1
vote
1answer
774 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, ...
3
votes
3answers
296 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 &...
0
votes
1answer
269 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 ...
0
votes
1answer
65 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 ...
1
vote
2answers
77 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?
1
vote
2answers
827 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: `'
1
vote
1answer
188 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 ...
1
vote
1answer
32 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. ...

1
2 3 4 5
13