2022 Developer Survey is open! 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
1 answer
60 views

Extract identifiers and corresponding brackets among overlapped brackets

I have some files contained identifiers as below: B#205918 A#273075 E#554065 Eg. sample of file1: ((((A#273075,A#273116),((A#224325,A#192952),A#243232)),(((E#7955,E#7165),E#6239),E#4530)),(((((E#3075,...
0 votes
0 answers
10 views

How to retrieve data from a logfile between time stamps in a bash script

I have a logfile that i am trying to 'grep' data out of via a bash script. The data i am specifically after is all lines between two timestamps (including the top timestamp) that have the pattern &...
32 votes
8 answers
98k views

Print odd-numbered lines, print even-numbered lines

I want to print the odd-numbered and even-numbered lines from files. I found this shell script which makes use of echo. #!/bin/bash # Write a shell script that, given a file name as the argument ...
0 votes
2 answers
18 views

Append a character at the beginning of next line matching the pattern throughtout the file

Test file: cat Test.txt #EXTM3U #EXTINF:100 a.flac #EXTINF:20 b.flac Expected Result cat Test.txt #EXTM3U #EXTINF:100 #a.flac #EXTINF:20 #b.flac Experiment 1 sed -e '/^#EXTINF/a #' Test.txt #...
3 votes
3 answers
1k views

Deleting 2nd character on each line with sed

Write a sed command that deletes the second character in each line in a file. sed -e 's/^.//' sample The above command deletes the first character. But how do you specify the second character alone?...
1 vote
0 answers
25 views

Rework sed for vim's errorformat for circom compiler

compiling ciruits and intend to use quickfix. but the compiler output was not in standard format ... so tried parsing Need help fixing the sed command preping the output for error format so that i ...
0 votes
2 answers
42 views

Sed script to AWK

I don't do this often, and when I do it is always time sensitive. I have the sed script below that extracts a number pattern from over a million files. I need to pike this to AWK, so when the ...
2 votes
3 answers
114 views

awk/sed split a cluster file in to multiple files

I have a cluster fasta file (called file) which looks like: >1AB2 >1AB2 AA NWWIEUNJRNIBGOWNGIOWGRBIGBRGRIOWGI NCIDHFR8EHGBVPIWOBGIGRI >1AB3 AA WNIOREHUEBRGOUERGHBERGIORBGREUGEGO ...
0 votes
1 answer
18 views

Not obtaining lazy evaluation using sed

I would have expected 'a' for this, why 'a:b'? $ echo "a:b:c" | sed -E 's/(.+?):.+/\1/' a:b
1 vote
1 answer
50 views

How to use find and sed to replace certain sentences in files

I am using find and sed commands to find and replaces the occurrences of certain sentences in the whole directory with some other sentences. For example if I want to replace all occurrences of the ...
0 votes
0 answers
36 views

change the bash output with stream editing [duplicate]

If I call bash like this: bash|sed 's/a/b/g' every time bash outputs an 'a' it is replaced with a 'b' $ bash|sed 's/a/b/g' $ echo aaa bbb $ exit However if I add additional substitutions like so: ...
0 votes
1 answer
91 views

How change first rows in column format of next's rows, replacing * by a number and perform operations between columns?

I have the following file which has the first two rows as if they were a single-column (i.e. a continuous string). I would like to separate them into columns and replace the "*" character with an "x" ...
2 votes
2 answers
84 views

Replace matched regex in file content with variables

I would like to do the following Search file content with pattern (^[ \t]*services:[ \t]*) If found, replace the pattern by a String (in variable) Else, append the String (in variable) at end of file ...
1 vote
2 answers
39 views

Couldn't get sed to match a group

I'm trying to do the below: echo "/Users/anon/Applications/Chrome Apps.localized/Spotify.app" | sed -E 's:([^\/]*$).*:\1:' which I assumed would capture Spotify.app and replace the entire ...
2 votes
8 answers
312 views

awk filter rows that only consist a single letter

I have a file (file1) that looks like this: ROW 1 AA 120 APFGHKDESFNNJFHGRIHJASFGNSKDHFIXXXXXX ROW 2 AA 234 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ROW 3 AA 122 XXXXXXXXXXXXXXXXXXXXX ROW 4 AA 89 ...
-2 votes
4 answers
128 views

sed or awk: replace only the n-th occurence of a string

How to write a sed (or awk, or both) which will take the following: echo '1 aa 2 2 3 bb 5 bb 2 5' | sed/awk ... And only replace the n-th occurrence of a string? For example the 3rd occurrence of 2 ...
3 votes
4 answers
38k views

create XML file using bash script

I want create simple xml file using bash script ( not with dom ) but when I set value in the line then echo print the $lorem word and not the val lorem=LOL echo '<root><foo a="b">$...
139 votes
15 answers
144k views

Decoding URL encoding (percent encoding)

I want to decode URL encoding, is there any built-in tool for doing this or could anyone provide me with a sed code that will do this? I did search a bit through unix.stackexchange.com and on the ...
16 votes
4 answers
40k views

find and replace with sed with slash in find and replace string

I want to change in file /var/www with /home/lokesh/www with sed command sed -i 's///var//www///home//lokesh//www/g' lks.php but this give error sed: couldn't open file ww///home//lokesh//www/g: No ...
0 votes
3 answers
65 views

How to add column based in the second line match using SED or another command?

I have the following lines result from zcat command 1 - URL Template: https://www.test.com 2 - Response: <200 OK,{Server=[nginx], Date=[Wed, 11 May 2022 01:05:06 GMT], Content-Type=[text/html; ...
2 votes
2 answers
91 views

Replace digits and then characters pattern with sed

I have a file like below: some arbitrary number of leading lines a prefix followed by wmd v0.0.0-20220406135915-ce5e3ee6c6bf some trailing lines This is only an example of what the file could look ...
44 votes
13 answers
38k views

Addition with 'sed'

I am trying to perform a mathematical operation with sed, but it continues to treat my variables as strings. The input is of this kind: $ echo 12 | sed 's/[0-9]*/&+3/' $ 12+3 I'd like to have 15 ...
0 votes
1 answer
54 views

Return content between corresponding brackets

I have a file with all type of brackets {}[]()- nested, open and close appropriately. I would like to return the content within the matching square brackets after the string (text:). The content of ...
3 votes
5 answers
271 views

Bash: sed or awk rewrite of numerical sequence

How to write a sed (or awk, or both) which will rewrite the following: echo 'v100 v201 v102 v300 v301 v500 v999 v301' | sed/awk ... to this output: v1 v2 v3 v4 v5 v6 v7 v5 i.e. each subsequent vx ...
1 vote
4 answers
54 views

Split the line into next line after a matching pattern

In the input file shown below, I am trying to find the string job_type and move the it to the next line if it matches job_type. I tried this, but it is not working: sed "s/[A-Z][a-z]*job_type:/\...
-1 votes
2 answers
41 views

Extracting data from a file with a regular expression in sed

How can I use sed to extract f607b9ab-1452-4758-b047-6b620591211b by using cmrepo-222-02 as my reference? ["+--------------------------------------+---------------+----------+------+-------------+...
-2 votes
3 answers
61 views

How to remove forward slashes from file in unix shell using sed? [duplicate]

I have the following file : / /FUSE // Bank S.A / N.V /F I want to remove all forward slashes (/), so that the result looks like this: FUSE Bank S.A N.V F How to do so using sed? Ive tried using ...
0 votes
1 answer
37 views

Trying to do a perfect sed replacement

I am trying to do a sed replacement which I am currently doing with two commands. I can't figure out how to combine the two commands together so that it replaces the words correctly in one go. My role ...
0 votes
5 answers
91 views

How to ignore all text containing special character more than once?

Sample Input: apple_ig rabbit_cat_ig dog_ig bird_duck_ig orange_ig goat_ig Expected output: apple_ig dog_ig orange_ig goat_ig I need to ignore all data that contains underscore _ more than once in ...
1 vote
2 answers
573 views

How to split vCards lines

Related to How to join vCards lines, vCard does a weird kind of line splitting: If a line contains more than 75 characters, insert a "CR, LF, space" sequence. Thus the following line: ...
0 votes
2 answers
66 views

How to replace all occurrences of a sequence starting with a given string to the next appearance of a symbol?

I would like to edit a huge single line file with thousands of occurrences of some string 'string_string': until the next appearance of a comma , (including this comma) and removing those occurrences ...
0 votes
5 answers
161 views

Delete columns that contains only numbers

I have a table that containes some data and I need to delete the columns that contains only number (Nr.,Cod,Tiraj): Nr. Autor Titlu Cod Tiraj Tara 1 Gauss Carl ...
22 votes
14 answers
98k views

Rows to column conversion of file

Suppose I have a file: File1: PAPER TEAM MANISH NISHA GARIMA JYOUTI ........etc File2 I want: PAPER TEAM MANISH NISHA GARIMA JYOUTI Rows to column conversion of File1.
0 votes
4 answers
74 views

Finding max row with highest value for a particular country in a csv file

I have a .csv file with entries like Location,Indicator,Period,First Tooltip Afghanistan,Malaria incidence (per 1 000 population at risk),2018,29 Afghanistan,Malaria incidence (per 1 000 population at ...
-1 votes
2 answers
62 views

How can I add space after filename of grep output?

I am using grep to search matching patterns inside files, and copy its filename from the output. Since I do this operation a lot I may end up copying : as well. Hence is it possible to add two space ...
0 votes
2 answers
78 views

sed command to fix concatenating two string literals

I'm looking for a sed (or other Unix utility) command to find all instances of two string literals being concatenated, such that the command will replace these concatenations with the corresponding ...
2 votes
3 answers
6k views

Replacing .* in vi

I need to replace all occurrences of "period asterisk" as it is shown here: blah blah .*:.*:.* blah blah with: [0-9][0-9]:[0-9][0-9]:[0-9][0-9] so that the end result looks like this: blah blah [...
34 votes
13 answers
13k views

There must be a better way to replace single newlines only?

I am in the habit of writing one line per sentence because I typically compile things to LaTeX, or am writing in some other format where line breaks get ignored. I use a blank line to indicate the ...
3 votes
2 answers
3k views

Modify filenames in Makefile

For reasons that are not important here, I have a source code that I process automatically file-by-file and the processed source files are renamed in a systematic manner. For example, I start out with ...
0 votes
1 answer
34 views

How to upgrade sed on RHEL 8?

I'm on a RHEL 8 system and by default sed 4.5 was installed. [root@192 ~]# rpm -qf `which sed` sed-4.5-2.el8.x86_64 [root@192 ~]# Since I want to use the --debug option to debug some sed commands, I ...
0 votes
2 answers
45 views

sed or other equivalent for grep with vfF

RHEL6.10 , gnu grep 2.2 grep -vfF stem.txt source.txt > filteredoutput.txt stem.txt has unique 13 digit numbers. source.txt is fixed length (400) data file where the 13 digit field value starts at ...
0 votes
1 answer
53 views

Include csv headers with sed [closed]

I have an csv file that looks like: id, name, nationality 1, Maria, ESP 2, John, NED 3, Alice, DEN I am building a document script.sed that executes different sed expressions like this: s/ESP/Spain/g ...
0 votes
2 answers
46 views

sed delete specific row

Delete the string except for the beginning of NM, how should it be written with sed input_file NF NM_001708.2(OPN1SW) NM_000374.5(UROD) NM_000235.4(LIPA) NM_021828.5(HPSE2) HPSE2, EX8-9DEL HPSE2, ...
-3 votes
2 answers
15k views

Add quotes around a value using sed

I created file called Test1.txt and I add a line. The file look like this, TEST = admin Now I want to add double quotes for TEST="admin". How to add double quotes using sed command? I want ...
0 votes
3 answers
86 views

Delete line in each text files if the first field value is greater than 400

I have a large number of txt files. the format of each txt files is similar to this 200 0.2 0.1 0.5 0.4 500 0.4 0.9 0.9 0.1 I am trying to delete each line in each txt file that has the first field ...
35 votes
9 answers
18k views

How to delete line if longer than XY?

How can i delete a line if it is longer than e.g.: 2048 chars?
0 votes
1 answer
54 views

Replace exact strings in a file based on a list of strings and a list of corresponding replacements,

I'm trying to do a dictionary based search and replace, but i'm having trouble figuring out how to make it case sensitive/exact match, but it is proving quite difficult. I have three files, fileA is ...
2 votes
1 answer
137 views

replace character only when it's not inside curly braces (sed, awk, tr, ...)

I have a string called "desktops" that look like this: desktops="1 2 %{F#990000}3%{F-} 4 5 6 7 8 9 0" The 6 digits after the "#" represent an RGB color, so the 3rd ...
0 votes
1 answer
27 views

Cut last value of a string [duplicate]

My data is like (a.txt) allheartweb.com whoisdatacenter.com domainsanalytics.com covercian.co.uk I want to extract all TLD from there My code is cut -d "." -f 2 a.txt its show me com com ...
0 votes
3 answers
105 views

Replace a timestamp Base64 value in a file

I have a problem, I have a file test.txt that has a content like this: dn: serv=CSPS,mscId=167e48dc2b7a42d4acce611c8b477262,ou=multiSCs,dc=three structuralObjectClass: CP1 objectClass: CP1 objectClass:...

1
2 3 4 5
135