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

learn more… | top users | synonyms

0
votes
2answers
34 views

Replace some text with sed

I have tried this to replace the resis_test by m.gds by searching the key word LAYOUT_PRIMARY. sed -e 's/\(LAYOUT PRIMARY\).*\1 /m.gds/' < FILE.ex > b FILE.ex LAYOUT PRIMARY "resis_test" ...
2
votes
3answers
162 views

How can I insert the contents of a file into a string in bash

I would like to append the contents of a multi-line text file after a particular line in a string. For example, if the file file.txt contains line 1 line 2 I'd like do so something like printf ...
2
votes
2answers
331 views

How to remove all CRLF in file (not replace with LF)

I'd like to remove all carriage returns followed by line feeds (CRLF), such as \r\n in a file. How can I do that? I can't use dos2unix because that replaces CRLF with LF. And I can't use tr because ...
3
votes
4answers
155 views

How to swap entire html blocks in multiple files with sed

I have tons of html pages with a simlar content as follows: <div class="wrapper"> <div class="aaa"> ...lot of html1 here like div's/spans etc.. </div> <!-- end aaa --> ...
1
vote
0answers
54 views

sed stdin behaviour

Using sed for a direct stdin treatment of data, I expect that a line is treated after the enter. This is what happens when I test on CygWin or Linux but on my AIX, a second new line is needed to treat ...
1
vote
2answers
135 views

Get current timezone on Centos 7

On previous version of centos , i used the following command to get the current timezone in my bash script timezone=$(sed 's/ZONE=//g' /etc/sysconfig/clock) Output is "America/New_York" How can i ...
1
vote
5answers
90 views

Using sed to cut a string starting with n spaces and ending with n spaces

How to use sed to cut text starting with x spaces and ending with y spaces? For instance This is my string: kkk 111 fff aaabbb 5d98 ccc mmmppp 9369d and I want to get this output: ...
3
votes
3answers
358 views

Strip off word pattern at the end of string using sed

I have following string: ksh -x SCRIPT2.ksh $BUSSINESSDATE & PID=$!; ksh -x SCRIPT1.ksh $BUSSINESSDATE & PID=$!; I want to strip off the last word & PID=$!;. Desired result is: ksh -x ...
2
votes
6answers
6k views

Extract substring using regular expression on a Unix file

I have file with below contents . /ABC/RTE/AD_900_VOP_123/OPP /ABC/RTE/TRE/AD_900_VOP_145/BBB /ABC/RTE/AN_900_VFP_124/FBF /ABC/RTE/HD_900_FOP_153/WEW /ABD/RDV/AD_900_VOP_123/OPP ...
2
votes
2answers
72 views

Search and Replace question

I need to find all occurrences of AAsomeArbitraryStringBB and replace it with CCsomeArbitraryStringDD. So AAHelloBB Text AAByeByeBB becomes CCHelloDD Text CCByeByeDD. It's important to note ...
2
votes
2answers
115 views

Extracting values from a file keyed by multiple keys

Consider a file with key=value pairs, and each key is optionally a concatenation of multiple keys. In other words, many keys can map to one value. The reason behind this is that each key is a ...
3
votes
1answer
42 views

Filter out inconsistent data blocks

I would like to filter out rows that has inconsistent geno values in line-part blocks. In case of duplicate consistent values , I would just keep the first row. As example, 'gf345 part1' has more ...
6
votes
8answers
6k views

Can sed remove 'double' newline characters?

I have a document with a lot of empty lines. How can I remove them when there are 2 or more together. I tried sed "s/\n\n//" file but it didn't work. No error.
1
vote
3answers
347 views

Pattern Search between specific lines and print line numbers

I have a file of 20 lines. I want to search for a string between the lines 10 and 15 and print the string along with the line numbers of the original file. I have tried sed -n 10,15p file | grep -n ...
1
vote
2answers
57 views

find and replace a value in a line of text

I have a text file which contain only 1 line of text 1314:Battery:1.90:50:30 I'm trying to figure out if is there anyway to do a grep and sed to change the value 50 and 30 to the following ...
0
votes
1answer
32 views

Prepending text read from a file on the top of another file [duplicate]

I want to add "void mainfunction()" on the top of a file. I am reading the actual name of the file from another file and the name of the main function from another file. I was using sed -i '1i void ...
2
votes
3answers
71 views

Rename mp3 file names to a pattern

I have a list of like names likes so: /A/B/C/D/E/F/filename_album1-003.mp3 its more like album\d+ I would like to change it to something like /A/B/C/D/E/F/filename_song-3.mp3 song is just a ...
0
votes
1answer
45 views

How can I replace string in a file?

I have the following line in a file, I would like to insert \N between two comma 20121128020001,2012-11-28 02:00:01.000,,,,,,,3.80,,,,, I tried to use seed sed -i 's/,,/,\\N,/g' Test.CSV Where I ...
2
votes
1answer
251 views

How to use variables in sed command

I'm trying to run sed -i "/$variable/c \$variable1' file.txt But it's not displaying any change in the file: file.txt. But the same command, with out the variables works fine: sed -i "/variable/c ...
3
votes
3answers
647 views

Need to insert single quotes in text file for use as SQL query using sed

I have created a line of text that looks like this: INSERT INTO radcheck(id, username, attribute, op, value) VALUES (,,00:23:32:c2:a9:e8,Auth-Type,:=,Accept); I want to use sed to make it look like ...
4
votes
5answers
11k views

removing the first and the last character of every line from command line

I am trying to remove the first and the last characters of everyline in a text file and save the resulting truncated version in a new file. Does anyone have an idea about how to do that efficiently ...
2
votes
3answers
1k views

Reverse match in sed, replace opposite of what was found

Say I have this output from my syslog, precalculated src_hash => 20 bytes @ 0x7f811c001e20 A6 2D E5 CD 2A BA F0 42 56 66 19 D4 61 1A E3 A0 .-..*..BVf..a... C7 5E 5F 77 ...
1
vote
3answers
245 views

Directory filenames with sed with whitespaces

I'm working on a script and I'm stuck, even with the help of the google. Here's my code: for FOLDER in `find . -type d | sed "s#^.#$(pwd)#" | sed 's/ /\ /g'` do echo "$FOLDER" done This will ...
5
votes
7answers
1k views

Replace a character except last x occurences

I have a file that has a bunch of hostnames correlated with IPs that looks like this: x-cluster-front-1 192.168.1.2 x-cluster-front-2 192.158.1.10 y-cluster-back-1 10.1.11.99 y-cluster-back-2 ...
3
votes
4answers
169 views

pattern match and capturing in unix

I have a file like this: A1-1915435_1_MIMAT0000069_MirBase_miR-16_microRNA_1_22-A1-1915435_1_ENSG00000206737_ENST00000384010_U1_snRNA_73_115 ...
2
votes
4answers
2k views

How to rename files with sed and csv

I'm new with Linux, sed, and awk but I don't mind challenging myself on new ideas. That being said, I understand the purpose and how to use rename and sed for a common event such as adding a $date or ...
3
votes
3answers
149 views

Extract lines between and including 2 patterns

I have a file with data structured as follows 1, p1, p2, p3, p4, p5, p6, p7 2, p9, p10,, 2, q1, q2, q3, q4, q5, q6, q7 2, q9, q10,, 2, r1, r2, r3, r4, r5, r6, r7 2, r9, r10,, 1, s1, s2, s3, s4, s5, ...
2
votes
2answers
99 views

How to avoid that an insertion pattern using sed is applied to the middle of a string?

Aim The aim is to convert the following string: hello_hello,123-world567-helloworld123456,world1234-hello09876 using sed into a specific format. Attempts sed -e ...
4
votes
5answers
229 views

how to split file and lines

I have a text file like : 1_01 { ; quite good spirals reset=2000 type=mandel passes=1 corners=-0.6014129278/-0.5990935452/0.427747516/0.429487053 params=0/0 float=y ...
16
votes
5answers
26k views

How to manipulate a CSV file with sed or awk?

How can I do the following to a CSV file using sed or awk? Delete a column Duplicate a column Move a column I have a big table with over 200 rows, and I'm not that familiar with sed.
5
votes
4answers
387 views

Remove next-to-last extension in a file name

Suppose a folder with many files with bad extensions,for example Song1.avi.mp3 Song2.avi.mp3 Song32.web.mp3 Song23.mp4.mp3 Song2a.mp9.mp3 I want to remove only the second field (web, avi, mp4). I ...
4
votes
2answers
586 views

Use sed or awk to join lines in a certain pattern?

Not sure on how to turn this input: A B C apartner bpartner cpartner into this output: A apartner B bpartner c cpartner I have this pattern in a 80 line file that needs to be 40 line. Also, how ...
4
votes
2answers
354 views

Replace or append a line with string within a file

I am looking for advice on how to search a part of a string within a file and replace the complete line OR append that string to that file if not found. I "played" with sed for a while now, but ...
0
votes
2answers
912 views

how to rename multiple files by replacing string in file name? this string contains a “#”

How to replace a text string in multiple files in Linux How to rename multiple files by replacing word in file name? Replace string in files with certain file extension Searching a number of files ...
0
votes
2answers
527 views

Removing a long string from php files - using grep and sed?

I have encountered some malware on my Linux server, and am trying to remove it from many php files. I've tried endlessly with grep | sed and grep | tr and couldn't even erase a simple text string, ...
4
votes
1answer
5k views

find & sed (search and replace)

I'm using the following command on my mac: $find . -name “*.java” -exec sed -i ’s/foo/bar/g’ {} \; and it seems to have no effect. I have two files in the directory that end in .java, which both ...
4
votes
3answers
135 views

Using sed to search for a string and print everything before and after within a range

I have this file: sometext1{ string1 } sometext2{ string2 string3 } sometext3{ string4 string5 string6 } I want to search this file for a specific string and print everything before this string ...
5
votes
3answers
3k views

sed: delete all occurrences of a string except the first one

I have a logfile with timestamps in it. Occasionally there are multiple timestamps in one line. Now I would like to remove all of the timestamps from a line but keep the first one. I can do ...
4
votes
4answers
122 views

Remove a character between 2 known strings

I have a data set like below: \"XXX \ START sapiodj \\" aj \d 2387 END hddo\" START bbcc \\" END ss My Requirement: I want to remove all occurrences of backslash\ and double quotes " between ...
6
votes
3answers
217 views

Replace uppercase to lowercase except first letter of each word in specific line

I want to replace names that I received in uppercase letters only. The names are mixed with other information which should stay as it is. AUTH: at the beginning of the line identifies it as a line ...
5
votes
4answers
164 views

Increment numeric pattern in file

I have a File that contains only the following line: BOF (REF-REQ0001 SW_requirement) EOF I need to generate a second file that would contain the following: BOF (REF-REQ0001 SW_requirement) ...
3
votes
4answers
152 views

tab separation of the file

I have a file with seq likes this ATCGTTTCTCAGCCTTTTGGCAAGACCAAGTGTAGTATCTGTTCTTATCAGATATTGGTATCTGCAGGCACTCCTGGAACCAAT ...
5
votes
1answer
252 views

How to ensure that string interpolated into `sed` substitution escapes all metachars

I have a script that reads a text stream and generates a file of sed commands that is later run with sed -f. The generated sed commands are like: ...
1
vote
0answers
20 views

Take the unknown contents of variable as literal in sed [duplicate]

I have two files: a.patterns contains patterns in a one per line way "`" "^" "<" "<(" "<)" "<[" "=" ">" "_;|^+*+?@" and b.data contains comma separated values. 1,1,0,"*",1 ...
0
votes
2answers
123 views

Extract multiple instances of text between two strings [closed]

I'd like to extract text between two strings in a text file that contains Spotify chart results Text file extract: ...
6
votes
3answers
227 views

sed with multiple expression for in-place arguement

I am trying to replace multiple words in file by using sed -i #expression1 #expression2 file Something 123 item1 Something 456 item2 Something 768 item3 Something 353 item4 Output (Desired) ...
0
votes
1answer
70 views

Need to swap the -(minus) sign for only numbers and not text for a given row

I have a input in which delimeter is <;| like given below:- 1-<;|3-Text <;|3.13-<;|0.28-<;|9 0.12-<;|2-Text <;|3.99-<;|4.11-<;|6 0.13-<;|3-Text ...
3
votes
2answers
8k views

Passing a variable to sed

I cannot not use a shell variable in sed in the $NUMBER form. I have this line in my shell script: cat shared.txt sed 's/whatever1/$2 ... whatever2/' > shared2.txt The result in shared2.txt ...
3
votes
1answer
77 views

sed repeating the last line in the stream

I have code in a script similar to this... smbconffile="/etc/samba/smb.conf" sed -i 's/.*[\[CMI\]]/\[CMI\$\]/' $smbconffile && echo "Success" || "Failed" sed -i 's/.*[\[LOCAL\]]/\[LOCAL\$\]/' ...
0
votes
1answer
54 views

replacing some text in square brakets in bash

I have this string that I get from running jack_lsp. a2j:Arturia BeatStep [28] (capture): Arturia BeatStep MIDI 1 in a xml file, I save the connections state from a previous jack session. ...