Questions tagged [sed]

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

Filter by
Sorted by
Tagged with
-2
votes
1answer
27 views

replace from position 11-30 and 48-70 in a file like below

File content: 11001153580234543456765 BC2015091429991231BC_23456765432234562 My code: sed -r "s/^(.{11})(.{17})/\1123456/" file.txt but this is not working and cutting down the extra ...
0
votes
4answers
55 views

Awk/sed to delete last column and add quotes?

I've got a file called test.txt and after some manipulations it looks like this: Metabolism # this header I need to keep Global and overview maps # this header I need to keep 01100 Metabolic ...
-5
votes
2answers
46 views

Change values of last column

I have input like this i tried to replace the last Grade columns with 9 as AB, 12 as RE, 23 as A1, 34 as FA is there any way to change the grade columns with said values. Input: ST NAME MATHS PHY ...
0
votes
0answers
41 views

sed script that replaces a line containing @ [closed]

I want to change an autostart file via script, i tried to use sed but anything is okay what can be found on Raspberry Pi OS. The autostart file: @lxpanel --profile LXDE-pi @pcmanfm --desktop --profile ...
1
vote
2answers
32 views

How can I remove multi-line (Lua) comments in a bash script?

I'm writing a bash script where I need to strip comments from Lua files, which are formatted: --like this foo="bar" --or like this --[[ or like this ]] --[[ or like this ]] I ...
0
votes
2answers
24 views

How can backup and then modify a file with sed?

I need to overwrite some configs on many servers at once and I want to modify the origianl config file while creating a backup, can all that be done with sed, just for curiosity? Someone was ...
0
votes
3answers
42 views

How do I delete a pattern in a column using sed command line?

I have a table like this below; "baseMean" "log2FoldChange" "lfcSE" "stat" "pvalue" "padj" "ENSG00000000003.14" 11....
0
votes
3answers
59 views

Selective extraction from patterned occurence (distant repeated lines) using awk or sed

A file has a line pattern where a line that does not contains numbers occurs twice in the file. Energy initial, next-to-last, final = -87057.8200168321 -87208.7223900015 -87208.7197287879 Energy ...
3
votes
4answers
224 views

match a part of a string and print the whole string

A command on my Ubuntu system prints the following output and I'm saving the output into a variable $problem_dbs: tacservices/e43ccb05-5b0a-4403-950b-9c91ed3f3694 unresponsive agent z1 10.213.197.77 ...
0
votes
2answers
71 views

sed printing titles

I am trying to make sed script that takes numbered titles and writes them in tree structure without the numbers: This is the input: 1. Text1 1.1 Text2 1.1.1 Text3 1.1.1.1 Text4 1.1.1.1.1 Text5 2. ...
2
votes
2answers
53 views

add comma separated variables in to file

I have a file into which I want to insert the string below: export TRUSTED_PROXIES='"172.16.0.0/12, 172.17.0.0/12"' [root@sasasas]# echo $TRUSTED_PROXIES "172.16.0.0/12, 172.17.0.0/12&...
-2
votes
1answer
42 views

Replace HTML Tag with SED

I`m trying to replace a html from several files using sed without sucess. I need to replace this: <link rel='shortcut icon' href='/admin/img/favicons/favicon.ico' type='image/x-icon'> with this:...
0
votes
2answers
32 views

Extract function string before function name with regex

I want a regex that would search for something like: package_name.some_function_name.foo() that would be part of a line and would and extract the some_function_namebut it should be able to work ...
0
votes
5answers
54 views

How can I separate numbers formatted as string (without space) into numbers with spaces based on the number of digits after decimal

I have a text file from a simulation where the numbers are without any spaces between them. An example is given below. I want to separate the numbers based on the decimal point number (13). 5....
-1
votes
3answers
58 views

I have a fix length file how to extract the data to looks like csv file

So I have the following file: HDR2013100120131001000000000000 ...
7
votes
2answers
138 views

Escape characters in sed transliterate

I want to use sed's transliterate (y///) to replace one set of characters by another. I would expect this to work just as well as using the tr program. $ echo '[]{}abc' | tr '[ab}' 'gefh' g]{hefc ...
0
votes
1answer
52 views

Sed substituiton for string containing both spaces and double quotes

I'm trying to use sed in a script to modify a line in my grub configuration file(/boot/grub/grub.cfg) each time grub updates. I wish to replace the following line: menuentry "Kali GNU/Linux" ...
0
votes
5answers
114 views

Search and replace lines AFTER a regex match using "sed"

This kind of feels like it would be easier in awk, but I'm curious if sed can do it. Here is my input: line 1 line 2 line 3 line 1 line 2 line 3 line 1 line 2 line 3 I'd like to write an in-place ...
0
votes
0answers
22 views

sed - change ip address on Cassandra configs on VM startup

I'm currently working on a disaster recovery setup in Azure we have a cassandra cluster running on one region. The plan is if the region goes down, we will utilize Azure Site Recovery to failover all ...
0
votes
2answers
50 views

Replace string with another one and vice versa

I have a folder structure like below: a/b/sample.txt c/d/e/sample1.txt Both sample and sample file contains the sentence My name is Debojyoti e/f/sample2.txt g/h/i/sample3.txt Both sample2 and ...
1
vote
2answers
56 views

swap position of consecutive multiple lines in after pattern matching

I am trying to edit a big text file. What I am trying to achieve is swap lines from positions between 3 and 14 to positions between 16 and 27. I have extracted UPDATE statements from MySQL bin-logs ...
0
votes
2answers
110 views

SED - replace line number with new text and variables in text file

I have problem using sed in Bash, could somebody help me? This sed command works fine... sed command sed -i '3s/.*/...test_text.../g' FILE.txt sed commnad + variables but I when I use variable in the ...
1
vote
1answer
35 views

How to remove every pattern match and write it in new file

So i have a long string that have no blanks and i want to remove every time the pattern match. This is how the string looks like: bdy11<entryunit="phoenix"><name>costperdps</...
0
votes
1answer
31 views

Search for specific part of a line

I want to have this script which will store users in the format:<$AccountName> <$DOB> <$Username><$Password> <$Email> on a file called Register.txt. I want to have it ...
0
votes
1answer
46 views

Remove and add a character at the beginning of the specified line in a dynamic file

I need to change a specific line of a file; first I will add a char and after some time I will remove that char. Adding a char to a specific line has been asked and answered in this question and works ...
1
vote
5answers
87 views

Append text on lines NOT matching pattern

INSERT INTO `db`.`table` VALUES ( 39741633 49302045 0 44 '{"CustomerName":"S","CustomerMobile":"8","CustomerEmail":"","VersionId&...
-5
votes
3answers
78 views

How to transform bash output to bash table [closed]

My output after running a program in bash looks like this (two rows, : limiter, four columns of data) #003:BMW:11:36 #004:Audi:2:35 I would like to convert that to a bash table like this Number Car ...
2
votes
1answer
43 views

replace pattern with new line in pipe input (not file but pipe)

I have an input stream which I do get with netcat. The input stream DOES NOT contain any newline characters. instead there are 4 spaces where there should be newline. So I need to replace each ...
0
votes
1answer
59 views

Extract last n lines and prepend chars with sed one-liner

Considering this file: 1 2 3 4 5 I can extract the last 3 lines with this sed one-liner: $ /bin/sed input.txt -e ':a;$q;N;4,$D;ba' But I would also like to add some characters (# ) in front of each ...
0
votes
2answers
57 views

Help with sed command

I need a sed command that will allow me to search for and display the info for all games released in the 1980's and alphabetize those results. Is there a good way to do this with only using sed? 1 ...
4
votes
6answers
329 views

Count and return how many replacements were done with sed in a file

I have a large JSON file in which I want to replace one string with another. It should not, but it might happen that this string would be used in a context where I do not want to replace it. I know ...
0
votes
7answers
223 views

Matching multiple ranges with sed range expressions [closed]

Update: As many commentators have pointed out, my question was ill-formed. Sorry and thank you! I am updating the my question but leaving the old question at the end for reference. Updated question I ...
2
votes
3answers
107 views

Replace a character only between the double-quotes with sed or awk [duplicate]

I have such a scenario inside a CSV file: ID,PRICE,QUANTITY,ARRIVAL 01299,"41,5",1,0 26528,"412,03",0,0 38080,"2,35",0,0 38081,"2,35",0,0 .. .. The question I ...
1
vote
4answers
46 views

How to add double-quotation to s3 bucket path with in a .tsv file using sed/awk in bash shell

I have .tsv file which contains the source and destination information of s3 bucket. I am using while loop to read source and destination path from that file and perform s3 cp operation. Please be ...
2
votes
2answers
87 views

Is it possible to remove specific repeated character of a list using regex?

I have a list of one column that contain ~ 100 lines, in which some lines are repeated, and my purpose is to get rid of a specific duplicate lines and leave only one copy, while the other lines kept ...
3
votes
7answers
610 views

remove trailing spaces from text files ONLY when necessary

I'm removing the trailing spaces using sed -i 's/[ \t]*$//' *.txt However, this command will rewrite all the files. Is there a convenient way to judge that if there are trailing spaces in a text file ...
0
votes
1answer
51 views

sed + delete all lines between two matching patterns and instead of them add a word as x=yes

here example of script when I did successfully deletion between two matching patterns ( the first is cat <<EOF | more and the second is read x ) the script #!/bin/sh cat <<EOF | more . . ...
3
votes
4answers
459 views

How can I duplicate a line and search and replace on the duplicate with sed?

I'm trying to duplicate lines in a text file that contain certain special characters, but in the duplicate, substitute the special character with "regular" ASCII characters. The concrete use-...
0
votes
2answers
41 views

Replacing wrongly escaped quotes with sed

I need to clean a very large CSV, which has wrongly escaped double quotes (\\" instead of \"). How can I replace all instances of \\" \\\" \\\\" ..... with \" or just ...
0
votes
3answers
72 views

How to replace empty lines followed by a specific string by this string?

With sed or awk or whatever, how to replace empty lines followed by a specific string (for instance & or \end{align}) by this string (hence & or \end{align})? As an example, here is the ...
1
vote
1answer
51 views

sed: -e expression #1, char 73: unterminated `s' command

I'm very new to SH and development and I'm blundering my way through the code one error at a time. I've come across this error now that I can not get to the bottom of. Any help would be great! I am ...
0
votes
1answer
39 views

bash replacing text in string with wildcard sed/ regnex

I am wondering if this is possible, I want to mass replace a text in various files, this is not a problem. What i cannot figure out, or even if its possible is to replace the text in a specific manner....
2
votes
3answers
142 views

sed: how to add text to first x occurrences

I am trying to add text to the end of a line the first x times it occurs. I know how to do it globally and for the n occurrence. I can't figure out how to do it for the first nth occurrences. An ...
2
votes
2answers
72 views

Comparing with csv file value

I have a csv file and I need to compare the value in 4th column of 2nd row with a string. Sample csv file: Col1,Col2,Col3,Col4 Val1,Val2,Val3,ValNeeded I'm using the below code to perform this, ...
0
votes
1answer
21 views

When assigning a command output to a variable, the new lines are replaced by white spaces [duplicate]

I have a file and the idea is to grep the content following a pattern ("create mode") and to store this content in a bash variable in order to use it then in a curl statement. I have the ...
1
vote
3answers
746 views

Explanation of a sed command

I found this interesting command: grep -v '^>' test.fasta | tr -d '\n' | sed -e 's/\(.\)/\1\n/g' | sort | uniq -c | sort -rn I have some grasp what it means (it counts letters from a text file), ...
2
votes
4answers
236 views

Reformatting text using sed or awk

I have a input like where first row is the header, is it possible to reformat the text as the output below? awk '{if ($2=="b" || $3 == "c" || $4 == "d" || $5 == "e&...
2
votes
3answers
185 views

using sed to capture groups

I have a file that looks like that: chr1 3143567 3143568 .3-2704 1.000000|ENSMUSG00000102693.2 chr1 3143599 3143600 .3-2705 1.000000|ENSMUSG00000102693.2 chr1 3143631 3143632 .3-2706 1.000000|...
1
vote
4answers
59 views

SED and REGEX for EXIF renaming

I was unable to comment on this old post, How can I rename photos, given the EXIF data? but it had a comment that seemed exactly what I needed so I started a new post, I hope not bad form. I get what ...
0
votes
3answers
56 views

sed for multi-line pick & delete

Given inputs in the format of set root='hd0,gpt3' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt3 --hint-efi=hd0,...

1
2 3 4 5
131