Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [sed]

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

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

split string using a substring as delimiter and get the later part

Here is my string LIBRARY_TRGT_CANV,CANV_MATCH<anything> I wish to get all the text after last occurance of our delimiter which is _TRGT_: Desired output: CANV,CANV_MATCH<anything> ------ ...
user avatar
  • 297
0 votes
1 answer
41 views

Need help Formatting a file having key: value [duplicate]

I have a file having the below values: cat data.txt server1: 'calv' server2: 'anot' log: '/u/log/1' server3: 'calv' server4: 'anot' server5: 'secd' server6: 'calv' LIB_TRGT_calv,anot: '/tmp/hello.txt' ...
user avatar
  • 297
0 votes
3 answers
67 views

bash insert backslash for every slash in string

I have a string that is a path: /tmp/something I need to escape the forward slashes with backslashes: \/tmp\/something How can I do this? Maybe sed? Please point me in the right direction.
user avatar
0 votes
3 answers
78 views

How to use crossplatform/standard sed between linux and mac?

Hi I have one script that was running inside makefiles for project deployments. I use sed inside it to capture environment and project name from input string and in ubuntu works great. This simple ...
user avatar
0 votes
2 answers
105 views

Using a regex search with sed to sort entries in a file

I have a text file of the following form: dir1/sub-dir1/.../filename1 author date dir1/sub-dir1/.../filename2 author date . . . dir2/sub-di2/.../filename1 author date dir2/sub-dir2/.../filename2 ...
user avatar
  • 101
2 votes
2 answers
101 views

merge multiple rows in specific columns

I have a file like this: xxx ax1 bx1 xxx ax2 bx2 cx2 xxx ax3 bx3 yyy ay1 cy1 zzz az1 cz1 zzz az1 bz2 ... I want the output like this: xxx ax1,ax2,ax3 bx1,bx2,bx3 cx2 yyy ay1 ...
user avatar
  • 155
0 votes
3 answers
57 views

Separate paragraphs using linux

I have a text file that contains connected paragraphs. I need to separate each paragraph with a blank line. Each paragraphs should begin with an >FP0 pattern, however because the paragraphs are ...
user avatar
  • 3
-2 votes
2 answers
95 views

How does this sed command to extract an IPv6 address work?

I was given a command to extract an IPv6 address: /usr/bin/ip a | grep inet6 | grep -vE 'fe80|host' | sed -e 's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' Could someone please break down the sed substitution ...
user avatar
  • 9
0 votes
1 answer
25 views

How to retain an ip address in sed while changing the netmask?

I have the following problem: I want to change the netmask of large number of ip adresses in Debian's /etc/network/interfaces because I am going to expand the network. After changing it I will use ...
user avatar
0 votes
3 answers
35 views

Adding matched string plus additional string after match in same line

I know the title sounds a little confusing, but hopefully my example will clarify my issue. So I have a file with a list of names (names.txt), for example: john david richard I'm trying to use a ...
user avatar
1 vote
5 answers
109 views

replace string x by string y according to string z

(EDITED) I have a file containing quite some problems. For example as below: Chr1_RagTag_p AUGUSTUS transcript 393571 396143 . + . transcript_id "TCONS_00000070"; gene_id "...
user avatar
  • 25
0 votes
2 answers
43 views

sed and variables-substitutions on an custom script

well i ask here because i have around 12 hours trying with examples on internet for put a replace with sed on a custom script. In the file a had a lots of lines but i want to replace values after &...
user avatar
  • 29
3 votes
1 answer
158 views

ignore whitespace at the beginning of a search pattern

This sed expression works, but is there a better way to represent the white space in both the search pattern and replace string? BRANCHTAG=7.17.9-main-5ee3e99d5ff002862d93728d821461033de1186d ...
user avatar
1 vote
2 answers
70 views

Replacing text with sed (without interpreting it as regex) [duplicate]

I am simply trying to replace text in bash, but having a hard time doing so. Other posts from years ago seem to result in an extremely complicated process, but I was hoping to get some easier and ...
user avatar
4 votes
6 answers
320 views

remove everything before a character in a column

I have a table like this start end chr 1 10 H300Chr01 10 50 H500Chr02 I would like to replace everything before "Chr" in column3. My desired output would be start end chr 1 10 ...
user avatar
0 votes
2 answers
69 views

How do I carry the last octet of the IPv4-address to the part changed by sed?

I am going to upgrade my network from 64 to 128 IPs. Of course I don't want to change it manually on all 40+ VMs. I plan to use an ansible ad-hoc command with sed -i and then use the same to restart ...
user avatar
0 votes
3 answers
108 views

Filter without relying to an html entity one line huge string based on a start end match and keep text in between the pattern no matter the length

I have a one line file like this Pastebin but way longer. My goal is to filter only parts of the string that example1: start with <a end with </a> example2: start with PZ end with s16 and so ...
user avatar
  • 121
-3 votes
2 answers
71 views

Copy the last column for the upcoming rows

I have a file that looks like this: FILE: 900 1 37 900 2 41 900 3 278 918 1 9999 918 2 9999 918 3 9999 And I want to obtain a new file which looks like this: 918 1 37 918 2 41 918 3 278 I want to ...
user avatar
  • 69
0 votes
1 answer
78 views

Why can't I match ] with sed

I'm trying to match either [ or ] in a character set in sed but for some reason it doesn't like ] $ echo 'foo [bar]' | sed -E 's/[\[\]]//g' foo [bar] The following works: $ echo 'foo [bar]' | sed -E '...
user avatar
  • 32.6k
-1 votes
1 answer
66 views

How can I remove the start and the end with sed?

How could I remove first ./ and the end / from my path? right now my code has: sed -i 's/dir2\/file-example.json//' test.sh and it prints out like this: ./dir1/ but I would like to have it like this: ...
user avatar
0 votes
1 answer
57 views

Remove 2 last directories from a path with sed

How could I remove last 2 directories from my path? Path example: ./dir1/dir2/file-example.json How I want it to be: ./dir1/
user avatar
-2 votes
3 answers
56 views

Search then replace it with last 4 characters

I have here a csv file with the following data 1,2,CC-12345678-20201120,6 1,3,CC-87654321-20201110,5 I need to replace the specific string after “CC-“ with its 4 last digit Expected output: 1,2,CC-...
user avatar
  • 1
0 votes
3 answers
121 views

How can I remove the second comma in each row of a csv file using sed?

I have a bunch of csv files in a directory, and I want to remove from each row the second comma. Example: Input: 53,900,1001,-45.4247,9.87187,541.65 75,900,0102,37.0896,4.24087,558.35 75,900,1101,37....
user avatar
1 vote
1 answer
60 views

Sum of Column with Rows Specific and write that value to .txt file

I have number of text files which has 70000 rows and 2 column. I would like to sum entries of 2nd column from 40000 to 70000 row and value of sum is to written to new text file. e.g:-Suppose Data1_old....
user avatar
  • 19
-2 votes
1 answer
43 views

AWK command ignores adding newline ending "\n" for blank line and print in one single line

When I use the below command, it adds \n to all the lines but skips for a blank line. awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' Example: Input: George Washington, 1789-1797 ...
user avatar
-4 votes
1 answer
79 views

SED - Create new line if finds ONE or ANOTHER MATCH

I have some files in a folder Each file has this structure: ... infos: '{"NAME":"Product","CLASSES":[255,107,255,108,255,255,0,0,255,255,255,255,255],"ISSALE":0,...
user avatar
0 votes
1 answer
39 views

How do I extract the content of quoted strings of a specific property path from an output?

I have an output from a web server response in JSON which looks like this: {"status":"OK","result":{"string":{"variable":0},"string2":[{&...
user avatar
  • 3
3 votes
3 answers
93 views

Sed replace with any random word in string

Hello I am trying to do a replace on a file where a string is followed by any random string using sed. My original file looks like below. access = read : [ * ], write : [ admin, sc_admin ] access = ...
user avatar
0 votes
0 answers
24 views

Retain colors from nodejs script after pipeing with sed

I want to include the contents of one JS file inside a nodejs file, so I've done it like so: NodeJS file: let requireJsBundleConfig = REQUIREJS_BUNDLE_CONFIG_CONTENTS ; // ...do stuff Bash ...
user avatar
  • 109
-1 votes
2 answers
58 views

SED - Generate line only if match some words in OTHER LINE [duplicate]

Assume I have 2 files in a folder ... product: Nike New Awesome Running Shoe price: 123 color: black ... ... product: Nike New Awesome Salloon Soccer Shoe price: 123 color: black ... I need to ...
user avatar
-1 votes
5 answers
85 views

SED - Generate line using some content of other line

I have some files in a folder Each file has this structure: ... product: Nike New Awesome Shoe price: 123 color: black ... I need to accomplish bellow scenario using single SED command, in all files ...
user avatar
0 votes
3 answers
114 views

How to print the text after the first occurence of a "start pattern"-"stop pattern" pair?

I have a file that contains a bunch of certificates: -----BEGIN CERTIFICATE----- AAAAAAA AAAAAAA AAAAAAA -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- BBBBBBB BBBBBBB BBBBBBB -----END ...
user avatar
  • 3
-1 votes
5 answers
111 views

How to make sure that the last character of each line of a file ends with single quote character

I have a file which has several lines. I wish to update the file while making sure that the last visible character of each line of the file is a single quote '. In case not, then we should add the ...
user avatar
  • 297
0 votes
1 answer
83 views

How to add single quote at the end of ONLY the last line of a file [duplicate]

I want a non-perl solution where I should be able to append a single quote ' at the last visible (non-escape characters) line of a file and save it back to the file. cat example.txt var1: 'funn' var2: ...
user avatar
  • 297
1 vote
2 answers
63 views

Using sed to remove string between < >

I want to remove the string between the first pair of < > Original text: < a href="ACM-Reference-Format.dbx"> ACM-Reference-Format.dbx < /a > I want to be left with just ...
user avatar
0 votes
2 answers
55 views

sed and awk in sh script not replacing text

The desired work to find a string, and replace to another (all occurrencies), and rewrite/update the file too. The file is an pbxproj file. I linked a sample of this file sample of the file (please ...
user avatar
  • 13
0 votes
5 answers
232 views

Remove the matching pattern from grep's output?

With bash, I'm running this: declare -p | grep 'declare -- ' That prints whole lines. I want to print those same lines, but I wanted to exclude the match itself. i.e., Can I do ... | grep pattern | ...
user avatar
3 votes
4 answers
245 views

Replace a base64 value in a file in unix

I have a problem, I have a file test.txt that has a content like this: objectClass: CPM1 objectClass: CPM2 objectClass: CPM3 objectClass: CPM4 objectClass: CPZ objectClass: CP04s objectClass: CP0A ...
user avatar
-2 votes
2 answers
61 views

I need to update a tag <abc><\abc> with variables from another file. Output should be an xml file with all those values comma separated within abc tag

I need help updating an xml file, file1.xml which has a tag name <abc> <\abc>. The file2.txt has numbers fixed length numbers (1 number in each row): 1234 5678 1435 I need output to a ...
user avatar
  • 11
0 votes
1 answer
40 views

Add value to a string

I have a large bash file that has a lot of lines like this: ... --env COMP_LABELS="service:service1" ... Where service1 differs in every line. (sometimes it's service:mgmt or service:admin)....
user avatar
0 votes
2 answers
64 views

Insert a text at a certain position with sed command on an xml file

I'm trying to figure out how to insert a text in an xml file with sed command. I started to try some basic commands with sed : sed -i -e ' <property name="prop1" ref="ANOTHER_BEAN&...
user avatar
  • 185
1 vote
1 answer
52 views

Automating Script Creation for Many Files

I am having trouble figuring away around this. I have some genetics files I need to filter. Due to the way my cluster is setup, It will time out before I can filter all the files/samples in the VCF. ...
user avatar
4 votes
2 answers
227 views

insert comment in the beginning of specified line in file

This is a pretty newbie question but what I am trying to do should be easy :( I am developing a script to automatically install a development environment but I need to comment out loadmodule in the ...
user avatar
0 votes
4 answers
71 views

Sed Merge split lines between two different patterns

I want to merge lines between ^pattern2 and its ";. Change this: pattern2 "xxx xxxxxx xxxxxxxx"; pattern2 "xxxx xxxxxxx xxxxxxxxx xxxxxxxxx"; pattern2 "xxxx xxxxxxx ...
user avatar
0 votes
2 answers
17 views

How to extract the first backup id from a shell output to a variable?

[user@laptop ~]$ cf adbr list-backups database Getting backups of database Backup ID Time of Backup bbf4277f-889a-4a9a-9274-683ed6e1553c_1647592205 Fri Mar 18 ...
user avatar
  • 3
0 votes
7 answers
115 views

AWK: Concatenate field from different records

Given file: 2018-03-22 foo/bar/baz 2020-09-30 Lorem/ipsum/dolor 2021-10-01 yadda/yadda/yadda 2022-03-14 blah/blah/blah (actual files contain thousands of such lines) How to obtain the string 2018-03-...
user avatar
2 votes
3 answers
229 views

Delete three lines in specific step

I have data like that (this is only a small part): 454SOL OW20704 0.317 0.251 5.525 454SOL HW120705 0.388 0.322 5.531 454SOL HW220706 0.229 0.290 5.553 462SOL ...
user avatar
  • 165
-2 votes
1 answer
34 views

Change the version number from 97 to 98 in an XML file [closed]

I want to change the version number with respect to the ip. For example for this ip 10.228.134.226, it should change the version number from 97 to 98 <qa:browsers> <browser name="...
user avatar
  • 11
1 vote
3 answers
46 views

Make unique a recurrent string in a file in linux

I have a file prueba.ldif like this: dn: EpsStaInfId=EpsStaInf,serv=EPS,mscId=0015f5e3d05d4d52b0cb85db69474db3,ou=multiSCs,dc=three structuralObjectClass: EpsStaticInf objectClass: EpsStaticInf ...
user avatar
2 votes
3 answers
129 views

sed: replace pattern using a list of variables only once

I am new to sed and would like to know how to replace a pattern with a different variable every time I have a txt file that looks like this: @K3KFV:1:1109:11598:25872 @K3KFV:1:2101:22577:15247 @K3KFV:...
user avatar
  • 23