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

learn more… | top users | synonyms

1
vote
2answers
35 views

Remove a line if regex exists only in 1st column of each line in a csv file

I have the following comma-delimited data (spaces used for visual clarity): 1 2014 23 2352 19.24 7.18 1 2014 23 2353 19.78 4.65 24 2014 23 2354 20.26 25.34 1 2014 23 2355 26.65 42.76 1 2014 23 ...
4
votes
6answers
105 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 ...
3
votes
4answers
84 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 </div> <!-- end aaa --> <div class="bbb"> ...
3
votes
2answers
672 views

Split log file by time range

I have a log file and would like to cut it into copies of 15min. In the log file the lines start with: dd mmm yyyy hh:mm:ss,xxx e.g. 12 Feb 2013 16:05:02,xxx log text... and the file rotates ...
16
votes
5answers
23k 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.
4
votes
4answers
221 views

How to run a command only if sed replace strings

I want to enable multiverse repository in Ubuntu by a command line. sed -i "/^# deb.*multiverse/ s/^# //" /etc/apt/sources.list && apt-get update This command will run apt-get update every ...
5
votes
4answers
319 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
506 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 ...
10
votes
2answers
40k views

Return only the portion of a line after a matching pattern

So pulling open a file with cat and then using grep to get matching lines only gets me so far when I am working with the particular log set that I am dealing with. It need a way to match lines to a ...
4
votes
2answers
123 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
28 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
505 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
4k 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
85 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 ...
4
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
91 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 ...
5
votes
3answers
100 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
109 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
134 views

tab separation of the file

I have a file with seq likes this ATCGTTTCTCAGCCTTTTGGCAAGACCAAGTGTAGTATCTGTTCTTATCAGATATTGGTATCTGCAGGCACTCCTGGAACCAAT ...
3
votes
1answer
125 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
18 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
42 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
192 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
56 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 ...
2
votes
2answers
5k 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
62 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
43 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. ...
3
votes
3answers
433 views

Replace %20 with a space in filenames? [duplicate]

I have a list of files that are using %20 to indicate a space in their names. I'm currently trying to do the following to change them all from %20 to a space " ". for x in *.txt do mv $x $(echo $x ...
0
votes
1answer
20 views

How to create a file name for the pipeline to delete all files?

So I want to delete all files in my current directory using the following pipeline: ls | sed -rn 's/(.*)\.jpg$/mv -n & \1.jpeg/pi' | sh How to create a file, named so that running the above ...
4
votes
7answers
696 views

Need some sed magic: Moving marked lines to the beginning of a file

I find myself in dire need of some sed magic (I really need to sit myself down and learn this). I have a file with lots of lines. After reviewing it, I've marked some lines by adding a star (*) to ...
-1
votes
3answers
66 views

Removing the special character “[” using sed

I have string "[9920380315,POSTPAID,0009,646.26,SELF,APPLICATION]" in that I want to remove first "[" but unable to do this using below command, sed 's/[//g' please help
2
votes
4answers
77 views

How do I use newlines inside () with sed?

When I want to replace, say Dot with Dot ##empty line## I do this: sed 's/Dot/Dot\ /g' Yes, a literal new line, this is the way it works on BSD sed. But, I can't do the same when the sed is ...
0
votes
1answer
55 views

Removing contents from a file

I have a file like this >gene1*ENSG24 CTTGGGGGGCTGGGGGCCAGGTGAAAGGGAAATGGAGGGCAGCACCCGCG AGCCCTCATTGCCTATAGTGGTTTCCATGGCGATCATGTAAGAGTCAATG TCGTCATTGGCAAAGTCGTCCGGGTGGGGTGTGCTGTAGGCAGAATCGGA ...
1
vote
2answers
25 views

Erasing in stdin all instances of regexes defined in a file

I am after something like a combination of sed 's/pattern//g' and grep -f patternfile.txt. Basically I would like the input stream to be stripped of all instances of the regex patterns defined in ...
4
votes
4answers
14k views

How to parse JSON with shell scripting in Linux?

I have a JSON output from which I need to extract a few parameters in Linux. This is the JSON output: { "OwnerId": "121456789127", "ReservationId": "r-48465168", "Groups": ...
4
votes
3answers
92 views

Insert text from file inline after matching pattern in another file

I'm trying to take the contents of a file and insert it after a matching pattern in another file using sed. My question is very similar to this question, but I wish to insert the contents of a file ...
2
votes
1answer
33 views

comparing 2 lists with additional data to be printed

I have a file lets say file1.txt ENSG00000223116 AL157931.1 ENSG00000233440 HMGA1P6 ENSG00000207157 RNY3P4 ENSG00000229483 LINC00362 ENSG00000252952 RNU6-58P I have another file say ...
1
vote
2answers
27 views

Parse command output [duplicate]

I want to only get the value associated to "cached" column of the free -m command. What is the most efficient way to achieve it? Something with sed or awk?
1
vote
3answers
167 views

Replace a string and replace it with a part of itself

I am cleaning up my data that is stored in text files. Each line starts with a category label followed by the actual data that I want to clean up. There are many text files in different subfolders, so ...
4
votes
1answer
69 views

Insert missing data within blocks

I`m a biologist and I am trying to solve this problem, please guide me on where to start. I do not know which forum to post this in, please let me know if this place is not appropriate. I have blocks ...
3
votes
2answers
57 views

How do I efficiently select specific line numbers from a list of records?

I want to take a list of numbers representing line numbers of a source file I want to filter and filter those lines from the source file. How I can build a unix pipeline to extract these lines from ...
8
votes
5answers
473 views

Convert file contents to lower case

I have temp file with some lower-case and upper-case contents. Input Contents of my temp file: hi Jigar GANDHI jiga I want to convert all upper to lower. Command I tried the following command: ...
0
votes
2answers
58 views

How to get portion of lines from all .txt files in a directory?

I have 5,000 text files of journal article citations. I am trying to extract only the abstract portion. Meaning that I want to keep the same text document and delete all the other text except for ...
2
votes
2answers
108 views

Remove escape characters using sed

I have input coming from pipe which contains special escape characters. For illustration, the stream looks like this: printf "foo.bar\033[00m" > file cat file How can I remove the trailing ...
4
votes
3answers
213 views

“parentheses not balanced” even though I escaped it?

Im trying to run this simple sed command sed '/VALUES\ \([0-9]/d!' It still gives me an error saying "RE error: parentheses not balanced" (yes the quotes are there). What can I do? I mean I could ...
1
vote
1answer
49 views

substitute complex text string in several files that contains special characters

I need to replace a complex string in several files in a directory. The string that needs replaced is: ...
0
votes
3answers
61 views

Strip the file base name, keep the directory part

I have a string which looks something like this dir/subdir/othersubdir/file.txt But it can also look like dir/file.txt or dir/subdir/file.txt Now, I am making a script where $P is the full ...
1
vote
1answer
25 views

how to move a header to the last column, using awk or sed

how to move a header to the last column, using awk or sed input file look like this: Line 1.000N x y z 23.88 44.66 56.6 23.81 41.66 53.6 Line 81.000N x y z 13.88 34.66 56.6 13.81 ...
8
votes
7answers
431 views

How to append Line to previous Line?

I have a Log file which need to be parsed and analysed. File contains something similar like below: File: 20141101 server contain dump 20141101 server contain nothing {uekdmsam ikdas jwdjamc ...
2
votes
4answers
3k views

Using sed, how to format one word per line, removing white space

I'm trying to replaces patterns and cleanup a file containing multiple words to get one word per line. The result is achieved using this command line: sed -e '/^[[:space:]]*$/ d' \ # ...