Questions tagged [sed]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
35 views

Unable to change config file with sed using groups and multiple lines

I'm trying to script changes in a config file (/var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla), which boils down to: [Update already installed software] Identity=unix-group:...
0
votes
6answers
67 views

Extract a path from text file using sed command

one.txt contents as below. Hi this is the first line in a file one.txt cooler:some default cooler string `/var/log/cooler_x86_64_someos8.4/config.cf' doing good nice! all is well Hi this is the ...
0
votes
0answers
66 views

Indent output even for partial lines

I'm trying to indent the output of 'subcommands' in a script, like this: Turning off image... Unmounting...done. Detaching loop device...done where the indented items are individual steps ...
0
votes
2answers
25 views

sed problem for Go templates documentation: Trying to replace “{{ foo.1 }}” with {{“{{”}}foo.1{{“}}”}}

I'm writing some documentation for the Go template language in Markdown, which has some complexities regarding paired double curly braces. Showing text surrounded by double curly braces requires ...
1
vote
3answers
48 views

sed: match pattern, and replace every occurence of a different pattern thereafter

Suppose I have aaaaabaaaaa, and assume that a can be an arbitrary pattern; likewise for b. How do I pattern match for aaaaaab, then replace all the aaaaa's after b with b's, but none of the a's ...
1
vote
2answers
83 views

Why must I call sed a second time after substituting spaces with newlines?

Given a file, I want to make a list of all the bytes it contains in octal format, each byte on its own line. Why does this work: #!/bin/sh -- newline=' ' od -v -A n -t o1 -- /tmp/file | \ sed -e "...
1
vote
2answers
40 views

How to change \n to space and \n\n to \n by sed?

I use sed to convert an srt file to a regular text file. Ansrt` file has a format of 1 00:20:41,150 --> 00:20:45,109 line 1 line 2 2 00:21:41,150 --> 00:21:45,109 line 3 line 4 So I use the ...
0
votes
0answers
28 views

Insert line under matched value using sed - error [closed]

I am trying to insert under a matched line of text within sudoers file. It appears that it doesn't work. Please could someone help? sed 'root ALL=(ALL) ALL/a someuser ALL=(ALL) NOPASSWD: ALL'...
3
votes
1answer
47 views

awk print pattern matched lines, and if a line with pattern1 has pattern2, then print line with pattern1 and nth line after as a single line

I currently have the output of a log, like the following. 20200124_075926.795633 [24_1859] [ERROR ] [PID] error running program: ... ... actual error message from n lines below ... 20200124_075929....
0
votes
1answer
25 views

How to replace spaces with _ for specific lines

I have a text file with multiple paragraphs. Each paragraph has headers with spaces. I want to replace the spaces of the text found between [ and :, with _ . Here is an excerpt of the text from the ...
0
votes
3answers
42 views

convert part of a line into hex

I have a file like so: some line some other line DisplayChoices=SAMSUNG yet another line ChipManufacturer=LG and yet another line ( there may be lots more of lines in the file, but the = sign is ...
1
vote
2answers
25 views

Replace string in a line, where the line is inputed by a variable [duplicate]

I want to replace a string in a line of a document, with sed. Where the LINE Number value should come from a variable, $var. I've tried: sed '%ds/peer/md5/g' $var ./temp.txt but it gives sed: -e ...
0
votes
1answer
42 views

sed '4!q' file name doesn't give proper result

I have one file which is having 10 lines. When I'm doing sed '4!q' filename Why it's showing only first line?
-1
votes
2answers
42 views

Need to add Spaces and commas in specific places

Need your expert advice Input: 2020-01-1713:57:5888823,aJ,MO,ZXC,adf 2020-01-1713:58:3878823,sJ,MO,AXC,Ldf 2020-01-1713:59:1898823,DJ,LO,AZC,NDf Desired Output 2020-01-17 13:57:58,88823,...
2
votes
2answers
61 views

I want to extract particular column from the file, column number is given in different file using shell scripting?

I want to extract particular column from the file1 by comparing with file2 in which column number is given that should be extracted from file1. File 1 (source data) look like this: 1 2 3 4 5 ...
2
votes
2answers
38 views

Extracting a json value from bash shell using awk without having to resort to both awk and sed

The aws command returns a json string to stdout inside a bash shell. $ aws ssm get-parameter --name /mysite/dev/email { "Parameter": { "Name": "/mysite/dev/email", "Type": "...
0
votes
1answer
34 views

SED - address N lines before end of file

Is there a simple way in sed to address a file, N lines before the end of the file? For example, when trying to insert the contents of a file, I can easily insert at the end with sed -i '$ r file2....
0
votes
1answer
12 views

Replace String in File with SED

The contents of the file as as follows: <?xml version='1.1' encoding='UTF-8'?> <sites> <site> <url>https://host.com/path/another-path/stable-1.630/update-center.json</...
0
votes
2answers
37 views

replace yaml field with content of file

I recently asked a question very similar to this one but failed to provide enough feedback for what would be a solution for this particular case. Opening this question with further information and ...
0
votes
3answers
22 views

Select and output particular string from a file

I have a file whose content is ae-scc-san-vserver01 /vol/ae_drac02_1_oradminvg_vol/ae_drac02_1_oradminvg_lun hdisk0 fcs0 FCP 150g C ae-scc-san-vserver01 /vol/...
0
votes
1answer
103 views

Fill blanks with adjacent fields with conditions

I want to fill(row-wise) blanks with "adjacent fields text" if the same or "X". Kindly suggest (AWK/sed) solution. (Additional requirement: Distance of empty fields matters while computing i.e using ...
1
vote
1answer
54 views

sed: jump to next input file

Is there an option or command similar to grep's -m1 or awk's nextfile for sed, which would allow sed to immediately stop processing the current input file when a match is found (while continuing to ...
1
vote
2answers
57 views

Split text separated by lines starting with semicolon

I have the output from a command (plantuml -language; see List of keywords, predefined names, symbols for codeless language module for BBEdit? for the background) which effectively looks like this: ;...
0
votes
2answers
30 views

Unix sed output coming pattern twice in replace

I've an XML file logback-spring.xml. Now, I want to replace string DEBUG with TRACE, wherever ref="logstash" occurs only in the next line. The input file looks like below: <logger name="com....
0
votes
1answer
33 views

Find field and replace content of field with another file content

I have two files: File1: not_keyword: 'something' keyword: 'condition' another_not_keyword: 'something' File2: condition 1 condition 2 condition 3 I would like to find all occurrences of keyword ...
0
votes
1answer
40 views

Why cant sed properly interpret this multi line pattern string?

I have a really large regex pattern string that I am using to delete INFO messages from a log file. When I use this all in one line like the following it works fine: sed -r '/([12][[:digit:]]{3}-(0[1-...
0
votes
3answers
52 views

Delete last x-number of lines in txt file if it contains characters, in bash

I have a list of .txt files in a folder and I would like to delete the last 50 lines (whole lines) IF they contain letter characters. So far I have the following: for i in *.txt do max_line=$(cat ${i%...
20
votes
5answers
3k views

What is the quickest way of replacing 0 by 1 and vice-versa in a stream?

Given a string composed of 0s and 1s, my goal is to replace 0 by 1 and vice-versa. Example: Input 111111100000000000000 Intended output 000000011111111111111 I tried, unsuccessfully, the ...
0
votes
1answer
29 views

Regex groups not greedy?

Are sed matches always greedy? I am trying to use sed to append an XML comment into an XML file as early as possible, which is right after the XML declaration if there is one. Something like this, ...
2
votes
3answers
231 views

How to write 2nd & 4th column to another file

Example: file1 Speed: 50.00 Temperature: 120.00 Speed: 51.00 Temperature: 121.00 Speed: 52.00 Temperature: 122.00 file2 50.00 120.00 51.00 121.00 52.00 122.00 I want to write file1 to file2
0
votes
5answers
100 views

Convert a comma delimited list of numbers to a hyphenated list or range

I have a comma delimited string of numbers as follows: 1,2,3,5,6,7,8,9,12,14 I'm looking for a command to use in a bash script that can combine adjacent numbers into range/hyphenated entries as ...
0
votes
1answer
50 views

Using sed with a variable in the pattern

I am trying to rename a couple of files with the same extensions with a differing variable in the middle. I have tried the following with no luck as to what I wish to accomplish. file: ...
0
votes
5answers
68 views

Write range of lines to file (1 to N) Bash,Awk, or Sed script

I've already extracted the line numbers needed from the input file (i.e 1 through N). I now need to be able to use the input file with this 1-through-N to output to a new file. The pattern matching ...
2
votes
3answers
33 views

How to sanitize XML attributes values

I have the XML like this: <string name="foo-bar">"bar-bar -bar"</string> <string name="asdf_qwe-rty" translatable="false">"Lorem ipsum"</string> Now, the name attribute can't ...
0
votes
1answer
42 views

Using grep & sed to add new line after a specific existing line?

I have been told that I can use grep & sed to find and change text in a file, but I do not understand enough to make it work for myself. I have a configuration file (lighttpd.conf) that I need to ...
0
votes
4answers
72 views

How to remove a string from a line

I am working on a property file containing list of Users: For Example JFR=abc1@abc.com,abc2@abc.com UserListApp1=abc1@abc.com,abc2@abc.com UserListApp2=abc1@abc.com AdminList=abc1@abc.com GlobalList=...
0
votes
0answers
42 views

How to replace ! by sed? [duplicate]

I want to replace &!@H with &@H using sed, but it did not work.I have tried Using sed to replace special characters this one but did not work.
0
votes
3answers
52 views

match string between two symbols and replace

I have a file with the many links like this: http://example.com/mall/mall/detail3.jsp?proID=2114280 http://example.com/mall/member/member/bookshelves/add.jsp?proID=3354136&productName=something ...
1
vote
1answer
56 views

sed: -e expression #1, char 10: missing command

I have seen StackOverflow answers on this question, but I am struggling to see how they apply to my problem because my special characters are escaped and adding a command to the end of the sed call ...
0
votes
6answers
83 views

How can I copy lines from multiple files into one file and name lines as the originated filename

My question is: I have 200 files in fata format. Such as: /User/Bin/bin.0.fa /User/Bin/bin.1.fa ... /User/Bin/bin.200.fa Each .fa file contains a contig name ID and nucleotide characters ...
4
votes
1answer
178 views

an XML without LF want to make it pretty using sed command in shell

I have a structure of a project in my git repository and would like to run a shell command in git bash to replace all the > with >\n (LF). I tried the following command: find . -name '*.xml' -...
2
votes
2answers
40 views

add Value in file with value of output generated with script

I have a txt/log file which has data- cat sample.log/(.txt) 500,3,2 there is script running which overwrite the value in sample.log. Instead of overwrite/or generating a new line I want the data ...
0
votes
1answer
54 views

SED: How can I use -n and -f together

I want to write a sed script where the echoing is off, like #!/bin/sed -n -f s/x/u/g but that gives my an Invalid option -- ' ' error. How can I do this?
0
votes
1answer
51 views

sed backreferencing with a command

I have a string STR="<trkpt lat="53.4829787887" lon="-113.518349362"><ele>682.0</ele><time>2020-01-09T01:00:01Z</time><speed>20.0</speed></trkpt>" and ...
3
votes
1answer
119 views

How to remove nodes from XML file as command line?

I have an xml file that contains the tag </w:rPr> several times. It is used like this <w:rPr><w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" w:hint="default"/></w:rPr> However ...
-1
votes
2answers
40 views

How to print text between 2 patterns with wildcards?

I need to capture the text between two patterns, but those patterns may contain numbers that change. Also I only care about lines with this structure that begin with that letter sequence, any other ...
0
votes
3answers
45 views

change a character above certain pattern

I have a file that looks like this: C 0.749421709 0.227878968 1.429202011 0.000039192 C 1.632642695 -0.091443576 2.542631832 -0.000184939 N 0.043615933 0....
0
votes
1answer
36 views

Sed with port forwarding in socat?

Not sure if this belongs on here, StackOverflow, or SuperUser. I have a device running a reverse telnet server that I need to be able to send/receive data to. I'm able to play with it if I run socat ...
1
vote
3answers
111 views

How to search and extract strings in Unix?

I was trying to download data using Yahoo Finance with wget but ran into some issues with getting cookies and crumb. I used BTC-USD in this case and I saved the crumb data in a file named "crumbstore....
1
vote
0answers
14 views

Unix Sed Command [duplicate]

Hi Could someone help to explain the meaning of the following syntax? I know it is regex but I could not understand s# sed -r "s#\{\"result\":\{\"status\":\"S\"\}\}##g" $data_get > $data