As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [sed]

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

Filter by
Sorted by
Tagged with
0 votes
3 answers
65 views

Replacing section in file with sed

I want to replace a section of the xorg file. Can this be done with sed? Original Section, i.e. replacing everything between 'Section "Screen"' and 'EndSection'... Section "Screen" ...
Andreas's user avatar
  • 101
-1 votes
0 answers
31 views

sed command to replace multiple patterns

I want to write a sed command, on a Linux amchine, to replace multiple patterns as below Below are the list of directories and files inside /tmp/felist: amb/eng/prf.amb amb/eng/det.amb bmb/menu.bmb ...
afrin's user avatar
  • 17
0 votes
0 answers
22 views

How can I replace spaces with colons with sed without "unknown command: `/'"? [closed]

I want to replace space characters with colon characters with sed. I tried the following, but it fails: $ echo 'word1 word2' | sed -e '/s/ /:/g' sed: -e expression #1, char 5: unknown command: `/' ...
Shane Bishop's user avatar
2 votes
4 answers
166 views

linux command using trim / cut / sed to cut few data in a file

I have the content like below in a /tmp/myfileslist test1/a/sample1.xls test2/demo.sh I want to remove .extentions and content before slash , also slash is to be removed.I want the output as sample1 ...
afrin's user avatar
  • 17
-3 votes
3 answers
88 views

add "#"on crontab line

I need to change a line on crontab with a linux command. I can't find solutions with the sed command. You can help me? The original line is: * * * * * root /foo/pluto/minnie.sh and must become #* * * ...
Riccardo Spuri Nisi's user avatar
0 votes
2 answers
71 views

How to replace two lines at once respecting indentation with sed?

I need help to replace the below 2 lines of code in a Python file with sed. We are loading one Python file which processes some data, so we need to replace the below 2 lines of code with another line ...
Abhi Ram's user avatar
-3 votes
1 answer
37 views

How can find special row and replace special strings

I wrote a todo list script with "add","clear" and "find" argument. I need to pass a "done" argument and script find related row and replace its first column ...
Danial Rostami's user avatar
0 votes
4 answers
86 views

How to join lines that meet until pattern until the same pattern occurs

I have a file : "p1"data "p2"data "p3"data "p1"data "p2"data "p3"data "p2"data "p3"data "p1"data I ...
C0ppert0p's user avatar
  • 125
1 vote
1 answer
48 views

sed command with five slashes

Any idea what this is supposed to do? grep -lr . | xargs sed -i '' -e '/ifcfg-wlan0/!s/wlan0/<name of the device>/g' I've never seen a sed command with five slashes, and I can't find any ...
Richard Barraclough's user avatar
1 vote
2 answers
61 views

Remove lines matching pattern, plus any lines following it matching a different pattern

Let me preface I am not sure if this question has been asked before, I have been Googling for answers but came up short. I want to use standard Linux/Unix commands (running this on FreeBSD) to exclude ...
ekrekeler's user avatar
0 votes
0 answers
23 views

How can place a newline before EVERY individual character in a file? [duplicate]

Ok, I may just be having a dumbass moment. If so, I apologize. It sounds like a fairly simple task, but I can't get this working: I'd just like to be able to input a string, and place each individual ...
Lee's user avatar
  • 91
2 votes
4 answers
83 views

Remove specific character strings from text file using sed, no change to output file?

Edit: added block quote text I have a tab delimited text file (acc.paired.txt) of illumina sample names (head): SRR10598163_R1.fastq.gz SRR8916417_R2.fastq.gz SRR10598049_R1.fastq.gz SRR10598163_R2....
Geomicro's user avatar
0 votes
4 answers
60 views

How to remove commas from a certain field in CSV?

There is a field/column in a CSV file Im working with called name, this is always the second field. The values in this column are like: "Smith, John" "Brady, Tom" "Manning, ...
ababa's user avatar
  • 1
0 votes
3 answers
50 views

Remove hostnames from URL with sed/awk

I got lists of urls with different domains and I want the hostname removed with sed, awk or something similar and only keep the path. There are no urls with port or username@password in it. input: ...
pwrsheller's user avatar
-1 votes
1 answer
21 views

search and replace with in a file, with unknown amount of spaces [duplicate]

I am looking for small help on search and replace a string in a file. my file content hostssl all all 192.168.10.1/16 pam pamservice=postgresql clientcert= 1 hostssl all ...
Durga's user avatar
  • 17
-1 votes
3 answers
109 views

How to replace the contents of out.txt with in.txt in a third file?

I have three files, main.txt, out.txt and in.txt. I want to replace every occurrence of the contents of out.txt in main.txt with the contents of in.txt. Both out.txt and in.txt may contain multiple ...
Roger Bosman's user avatar
0 votes
0 answers
27 views

replace hex value to random hex value with the same length in pcap file

I need to replace hex value to random hex value with the same length in pcap file. I work in debian 10 in bash. I have pcap file for example with this tcp payload in some packets: I want to replace ...
Mexanizm456's user avatar
0 votes
4 answers
51 views

extract user id and 1st inital last name from output

Getting the output of user identity with getent passwd. How can i change the output from u12345:John Doe to u12345,jdoe i got it with sed but it it removes u12345 but does give me jdoe
mike's user avatar
  • 1
1 vote
5 answers
47 views

Sed - match up to, but not including, pattern, with newlines included

I have an input that is in a multi-fasta format. Essentially: >header1 AAAAAATTTTCCCCGGGG AAAATGTGTGTCTCTCTC ATAGGATGAGT >header2 GGGGTGTGTGATGTAGTA AAAATGTGTGTCTCTCTC ATAGGATGAGT .... >...
Laura's user avatar
  • 199
2 votes
5 answers
80 views

How to replace a 10 digit sequence using sed

Using 'sed' I want to replace any 10 digit sequence with 1234567890 This works but is not very elegant echo "code=1111111111" | sed 's/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/...
Roger Mungo's user avatar
-2 votes
1 answer
22 views

How to delete the whole row when it starts with 'H' in a comma separarted csv file [closed]

How to delete the whole row when it starts with 'H' in a comma separated csv file for below example, H,NYR,257,10,11,000, TESTING,055,000,2023-05-10 D,NYR,257,10,11,000, TESTING,055,000,2023-05-10 H,...
guest's user avatar
  • 1
0 votes
3 answers
81 views

Need assistance with awk/sed to identify/mark duplicate IP addresses

Good day. I have a text file which contains pod/node names and associated IPv6 addresses of which two pods have the same IP address, first pod k8-worker0001c-cif-9d86d6dd4-vf9b9 and last pod k8-...
Bjoern's user avatar
  • 29
0 votes
2 answers
34 views

Use changing string as template for insert via bash

I have a file that needs some inserts. The inserts are depending on existing strings within the file which i can identify with a keyword in the corresponding file. The insert itself is supposed to ...
Yamira's user avatar
  • 3
3 votes
6 answers
227 views

How to reverse lines inside repeated blocks in a text file (using sed/awk?)

I have a file like this: x = { y = { z = { block = { line1 line2 line3 } } } } x2 = { y2 = { block = ...
farraget's user avatar
0 votes
0 answers
54 views

Get coordinates with xdotool upon user click and use them in an automation script

I am trying to prompt the user "Click the confirm button" and use the coordinates as a variable in a script. If the user clicks at 1285 786, I would like to click this coordinate once and ...
PerryJones's user avatar
3 votes
3 answers
335 views

Find files matching one pattern, but not another, using grep, awk or sed [duplicate]

I need to locate .php and .pl files that do not contain one string (e.g. aaa), but do contain another (e.g. bbb). I'm currently using this command: find /path/ \( -iname '*.php*' -or -name '*.pl*' \) -...
Krackout's user avatar
  • 2,460
0 votes
0 answers
28 views

list all the lines of an output that are not in the contents of another file

I have a directory of files. I want to check which of these files are not listed in the contents of another file, (content.txt). content.txt contains the file names, but also contains some text before ...
karizma's user avatar
  • 211
0 votes
4 answers
66 views

sed: Replacing successful as the condition

I bumped into an excellent use of sed to do replacing, and use its successful state as the condition to print the line: $ seq 3 | sed -n 's/2/B/ p' B I'm wondering if this short form can be extended ...
xpt's user avatar
  • 1,093
0 votes
1 answer
43 views

Replace xdotool key value with user input

I am trying to write a script that allows a user to input a number and change an xdotool key value to that input. Key inputs in xdotool must be separated by a space, for example xdotool key 1 2 8; So ...
PerryJones's user avatar
10 votes
8 answers
1k views

Convert only all-uppercase lines to lower-case

As an example, say I have: One, Two. OnE, Two. ONE, TWO. And I want to replace only the lines with all upper-case with lower case so that I get: One, Two. OnE, Two. one, two. I am trying: gsed '/[a-...
user3338049's user avatar
0 votes
1 answer
46 views

Breaking command output into new lines instead of refreshing the same line

I'm trying to write a script that involves SnapRAID, where the progress output of snapraid sync is timestamped and logged to both a file and stdout. The issue I am facing is that snapraid sync outputs ...
MrMeeb's user avatar
  • 3
0 votes
1 answer
42 views

Correcting typo in PDF, other solutions aren't working

I have a job interview on Tuesday, and I need to correct a typo "obestiy" [sic] to "obesity" in a PDF from LaTeX that I cannot recompile due to missing images and tables. I have ...
con's user avatar
  • 109
0 votes
3 answers
113 views

Adding 10 whitespace characters using sed

I have written a script that replaces a string, but I need to add the 10 whitespace characters back. I can add it back by pressing space 10 times, and that works, but this looks hideous in my script. ...
user898458's user avatar
0 votes
2 answers
53 views

Perform search for text formatting on last row of text using awk or sed

I have output with many rows. The number of rows on the output is inconsistent. Is there a way that the last row can be selected so that a character may be found and replaced? If not using awk or sed, ...
XJMZX's user avatar
  • 35
1 vote
3 answers
84 views

Extract version number from github repo

Hello I'm trying to extract a version number from a github release site. Which I later need for a Ansible role. For example I want to get the exact neovim version number of the latest release from ...
edinazzu's user avatar
2 votes
3 answers
187 views

Replace the last half in every line of a file with corresponding part in another file

I have two files A and B. Every line in both files is considered an item. The format of every item is fixed, consisting of a key and description, separated by a space. as shown in the example below. ...
echo's user avatar
  • 21
0 votes
3 answers
72 views

grep from a specific value to specific value

For example, I have a file with data: [2023-03-21 12:27:19 +0000] some_data [2023-03-21 12:27:19 +0000] some_data [2023-03-22 12:27:19 +0000] some_data [2023-03-23 12:27:19 +0000] some_data [2023-03-...
Mexanizm456's user avatar
0 votes
2 answers
135 views

Modifying a path

I'm trying to modifying a path stored in a variable ($var) through sed. In truth, I need to replace $(dirname "$var") for reasons related to the purpose of my script. An example of var is ...
user9952796's user avatar
1 vote
4 answers
207 views

Remove lines from a file that begin with and do not end with in bash

I have read many sed examples on how to remove lines beginning with a specific character or character set which is not challenging but I cannot seem to crack this one. I want to remove all lines in a ...
robetus's user avatar
  • 113
-2 votes
2 answers
80 views

Select all the text or characters between 2 text patterns that are repeating

Following is the sample .log file (there can be more lines in this) 2022 User abc (iii) 2023 defaa <party> ttt 2222221 User def (bbb) 20222 defaa <accoun> ttt 2222 User dddd (aaa) 3333 ...
John Doh's user avatar
0 votes
3 answers
94 views

How to replace certain characters to CR+LF between two words

I want to generate a csv file to tell what server(s) have particular files and ownership. Here's the original output I got: server01,server02,server03,owner,/etc/file1 server04,owner,/etc/file2 ...
NeilWang's user avatar
  • 272
0 votes
3 answers
109 views

How to delete all text before and when string occurs on sed

I remembered how to do this and even learned it from Stack Exchange, but forgot how I googled it so now I can't find it. The answers I am finding now are not what I'm looking for. Here is an example ...
Etcetera's user avatar
0 votes
3 answers
79 views

Using "sed" to insert text at the end of a field in TSV file

I want to insert characters in TSV files using the sed command with wildcard expressions: I have a file like this: Marker Pvalue Trait Chr Pos S3_16887238 6.172847e-09 Total_Soil_S 3 ...
Vinod Kumar's user avatar
0 votes
1 answer
91 views

sed replace block of yaml code with nothing

I am trying to use sed to remove a piece of code from a yaml file. what I have so far is the below code, but it does not work. sed -i 's/- node-service\/velocity_log_deployment((.|\n)*)//' config.yml ...
xerxes's user avatar
  • 333
1 vote
1 answer
75 views

Using sed to find and replace node version in certain files

I am trying to use sed to replace node version matches in certain files The following is what I have come up with but it leaves certain digits or characters after replacement and is not replacing the ...
xerxes's user avatar
  • 333
0 votes
1 answer
48 views

sed issues when working with tab? Should I use awk instead?

cat file.tsv| sed '1icolumn1 column2 column3 column4 ...' > file2.tsv I am using sed to add a first line (header labels) for a .tsv file. The labels should be tab separated. I have been ...
Visio1288's user avatar
  • 113
2 votes
1 answer
151 views

bashrc alias using ticks and backticks not working

I would like to create in .bashrc an alias which executes the following: virsh list --all | sed '1,2d' | sed '/^$/d'| awk '{print $2" state:"$3" "$4}' I've tried in different ways ...
Marius Ardelean's user avatar
0 votes
3 answers
151 views

Shell extract full word matching partial pattern

I need to extract a word from a line in a shell script, I've seen similar examples though none of which worked. Take the example sentence word1 word2 word3/pattern/word4.word5 word6 Given pattern it ...
Morten Nissov's user avatar
1 vote
4 answers
87 views

Remove last line of file by any user, owned by root

I have a file with permissions 666 so users can edit it with a different script. This works. I need to script to remove the last line of the file, however this is not working as using something like ...
Dave's user avatar
  • 474
0 votes
0 answers
57 views

Replace a string in a column of a text file based on matching string listed in another file

Following my previous question I have multiple set of file, so I greped on list and wanted to change other file by using grep file.txt for example I am pasting three file here File 1 chr - seq1 ...
umar's user avatar
  • 17

1
2 3 4 5
144