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

learn more… | top users | synonyms

0
votes
3answers
35 views

sed remove last space only on end of line,combined with awk

I have those line Siouxsie Sioux Siouxsie Sioux ... Sylvia Tobias Sylvia Tobias ... Sydney Urshan Sydney Urshan ... Club Drummer (uncredited) Club Drummer (uncredited) ... ...
0
votes
2answers
40 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
3answers
1k views

Using a here-doc for `sed` and a file

The title says it all, I want to use a here-doc for sed commands and provide the file to be read and the output file. I've looked at Here-Documents from Advanced Bash Scripting guide but it does not ...
3
votes
4answers
3k views

extract only the substring after double quotes - grep

I have a file which is as below. <a href="http://firstlink.com" title="title1"> <a href="http://secondlink.com" title="title2"> <a href="http://thirdlink.com" title="title3"> <a ...
4
votes
7answers
538 views

Remove everything that is not a 4 character number

I need to remove everything that is not a 4 character number such as 9838, 6738, 1337 or 1889. I though that this command would work: sed 's/....[^0-9]//g' . Means any character in regex, and ...
3
votes
2answers
35 views

Coloring tail output with perl

tail -f logfile.log | perl -pe 's/.*foo*/\e[1;41m$&\e[0m/g' will color all the lines containing the pattern "foo" in the logfile.log file. How can I make use of this in order to highlight ...
5
votes
2answers
3k views

Single command taking two strings to extract string between them, like 'tr' (without expressions)

Saw here a way to use sed to get text between two other strings in a line, like: sed 's/.*starting_text\(.*\)ending_text.*/\1/' but I'd like a simple command (like tr, but for string extraction) ...
3
votes
2answers
629 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 ...
0
votes
1answer
37 views

sed command to print all line starting from and end to specific words present in a file

Suppose I have one file File1 consist two Words File1 : PAPER TEAM Now i need to print all the lines of a file M starting from word PAPER end to word Team sed command to print between two words ...
6
votes
6answers
279 views

sed - remove the very last occurance of a string (a comma) in a file?

I have a very large csv file. How would you remove the very last , with sed (or similar) ? ... [11911,0,"BUILDER","2014-10-15","BUILDER",0,0], [11912,0,"BUILDER","2014-10-15","BUILDER",0,0], ...
3
votes
4answers
283 views

How to use sed to selectively remove leading zeros

How can I substitute/remove 0's in this, using sed: 2001:0db8:03cd:0000:0000:ef45:0006:0123 to make it looks like this: 2001:db8:3cd:::ef45:6:123 There are 8 pieces of 4's divided by : in the ...
6
votes
4answers
13k views

Can sed replace new line characters?

Is there an issue with sed and new line character? I have a file test.txt with the following contents aaaaa bbbbb ccccc ddddd The following does not work: sed -r -i 's/\n/,/g' test.txt ...
11
votes
5answers
33k views

How to strip multipe spaces to one using sed?

sed on AIX is not doing what I think it should. I'm trying to replace multiple spaces with a single space in the output of IOSTAT: # iostat System configuration: lcpu=4 drives=8 paths=2 vdisks=0 ...
2
votes
5answers
118 views

Remove backslashes from a text file

I have Input: NISHA =\455 Output: NISHA = 455 I want to remove \ from output. I tried to use command sed "s/[\]//g" P but it is not working and it flags an error: character found ...
2
votes
2answers
176 views

Why does sed outputs “char 53: unterminated `s' command”

Why this bash script ssh $SERVER bash <<EOF sed -i "s/database_name: [^ ]*/database_name: kartable_$ME" $PARAM_FILE exit EOF output -> sed: -e expression #1, char 53: unterminated `s' ...
-1
votes
0answers
18 views

Grabbing table name from views definition using sed

I am little new to linux so please excuse me for my ignorance. I have a text file which basically lists out the view definitions in the database. What I need to know is that what are the tables ...
13
votes
8answers
2k views

Replace string containing newline in huge file

Anyone know of a non-line-based tool to "binary" search/replace strings in a somewhat memory-efficient way? See this question too. I have a +2GB text file that I would like to process similar to what ...
1
vote
4answers
131 views

SED command not replacing (working regex)

I'm trying to replace in one of my projects all mysql to mysqli, with their parameters. To do so, I'm searching for all files with mysql in my folder recursively and replacing it with mysqli. Ex: ...
1
vote
3answers
61 views

Generate networking configuration files using sed and bash

I am a bit rusty on my scripting abilities and am trying to find a good starting point for creating a script that creates files (generating new file names) and edits the IP address in the file by ...
0
votes
2answers
37 views

how to insert backslash at the front of # symbol?

In bash programming, given a variable, say varA, that store a string containing # symbol. Let's assume varA contain this value: ASD# 1, I need to append a backslash \ at the front of #, so the output ...
3
votes
3answers
24 views

Parsing Log Files with sed -e. Need to count unique class names

I have a file, let's call it filename.log, in it I have something like this (2014-11-18 14:09:21,766), , xxxxxx.local, EventSystem, DEBUG FtpsFile delay secs is 5 [pool-3-thread-7] (2014-11-18 ...
3
votes
5answers
165 views

removing extensions in a column

I have a file like this ILMN_1343291 TGTGTTGAGAGCTTCTCAGACTATCCACCTTTGGGTCGCTTTGCTGTTCG NM_001402.5 ILMN_1343295 CTTCAACAGCGACACCCACTCCTCCACCTTTGACGCTGGGGCTGGCATTG NM_002046.3 ILMN_1651209 ...
8
votes
6answers
408 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 ...
1
vote
1answer
87 views

sed: -e expression #1, char 4: unknown command:

Could someone tell me what does this reply mean ? sed: -e expression #1, char 4: unknown command: ` ' I get it when I use : sed -n "$num"p $javaFile >> ~/Desktop/$1_sql.txt for i in `seq 5 ...
4
votes
3answers
148 views

Change case of n-th letter in a string

I want to change the case of the n-th letter of a string in BASH (or any other *nix tools, e.g. sed, awk, tr, etc). I know that you can change the case a whole string using: ${str,,} # to lowercase ...
2
votes
2answers
117 views

Left and right square brackets treated differently by sed/bash

I have a file with the following contents: [root@server list]# cat filenames.txt [AAA','ACMEDEMO2','ACMEDEMO3','ACMEDEMO4','RENTCOGH','TESTENT','DORASINE','LOKAWINK','BBB] [root@qa4app01 list]# I ...
2
votes
3answers
3k views

sed - how to replace a single quote?

This works fine: sed -i 's# @driver.find_element(:xpath, "//a\[contains(@href,##' temp_spec.rb against a source of @driver.find_element(:xpath, "//a[contains(@href,'change_district')]").click ...
1
vote
1answer
20 views

sed: subsitute in line that contains X but does not contain Y

I am looking for an elegant solution that combines both of these commands: sed -i '/Y/! s/replace/with/' /path/to/file sed -i '/X/ s/replace/with/' /path/to/file I tried sed -i '/X/ /Y/! ...
3
votes
4answers
61 views

Replace a marker in a text file with arbitrary new text

I have a file which contains some text and - on a single line - a marker which indicates where new content should be added foo bar %SUBSTITUTE% foo The line line substitute should be replaced by a ...
3
votes
2answers
198 views

Delete every Nth line in shell

I'm trying to delete a line after N lines using awk and I can't seem to get it right. The file format is like this YYYYYY XXXXXX XXXXXX YYYYYY XXXXXX XXXXXX The real example would be office3 3 1 ...
7
votes
4answers
304 views

Output part of each line to a separate file

I have a file like this: a AGTACTTCCAGGAACGGTGCACTCTCC b ATGGATTTTTGGAGCAGGGAGATGGAATAGGAGCATGCTCCAT c ATATTAAATGGATTTTTGGAGCAGGGAGATGGAATAGGAGCATGCTCCATCCACTCCACAC d ...
2
votes
4answers
137 views

remove leading string in bash

I try getting this sed command to work. I have a string like rev00000010 and I only want the last number, 10 in that case. I have tried this: TEST='rev00000010' echo "$TEST" | sed ...
2
votes
4answers
3k views

remove white space before delimiter with sed

I have data of the following format that I want to input into LibreOffice calc data | num | num | num | num For some reason Libreoffice does not think the string "3214 " is a number by ...
1
vote
1answer
31 views

How to replace a symbol in sed only if it occurs before a letter?

In my documents, I have lots of occurences like these: [["A [["b [["8 [["c [["F [["1... What I need to do is to replace double brackets with single brackets, but only if there is a letter after a ...
3
votes
3answers
167 views

Extracting part of lines with specific pattern using awk,sed

I have a question regarding the awk/sed operators. I have a big file which has following set of lines repeated Expression loweWallrhoPhi : sum=-6.97168e-09 Expression leftWallrhoPhi : ...
1
vote
2answers
88 views

Search 2nd line of files and print filenames to stdout

I have a few directories of ~10,000 files. What's the quickest way to search each file and return the filename if the second line contains a specific string? Edited for clarity
5
votes
2answers
4k views

How to replace a left parenthesis with sed?

I have to replace ( with some character in my file, and I can't do it. \( is used for grouping in sed and when I used \\( with sed, it treated it as \( character not as just (. It seems like a tricky ...
4
votes
2answers
355 views

How do I populate end tags using sed, awk or any other command?

I have a txt file that looks like this: <sss>ss< or <firstword>anotherword< I want it to look like this <sss>ss</sss> or ...
3
votes
3answers
207 views

How can I delete all text between curly brackets in a multiline text file?

Example: This is { the multiline text file } that wants { to be changed } anyway. Should become: This is that wants anyway. I have found some similar threads in the forum, but they don't seem ...
1
vote
2answers
40 views

How can I use sed to remove the first paragraph of the file?

So the paragraph is defined by having a empty line at the end. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et nisi tristique, facilisis orci nec, pellentesque tortor. ...
3
votes
6answers
118 views

how can I use sed to replace the lists that begins with (*) in a file

Using sed how can I replace the lines that start with a star and replace it with numbers starting from 1? I need to replace the (*) in the fist of a list with numbers using sed for example > this ...
5
votes
7answers
800 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 ...
4
votes
3answers
142 views

Use sed to delete all but a certain pattern

How do I get just the link part in the http-source of a link? I have <a href="http://unix.stackexchange.com/users/20661/">Unix &amp; Linux and would like to get just ...
1
vote
5answers
64 views

Regular Expression for Mixed cased words

I want a regular expression that will help me identify if a certain pattern is present as a mixed case in a sentence or not. Say: Fox juMPed the rock Now, I want to find that if the pattern ...
2
votes
2answers
57 views

Parse several thousand lines of txt into lines and columns

The file at hand lists names, credentials, roles, and privileges for thousands of users. It was passed onto me as .xls but the lines and columns are not arranged in proper form. I have reformated ...
1
vote
4answers
60 views

How to use regex in sed?

I need to revoke the sudo access to the user using sed in scripts. I want to comment the user only if the line contains /bin/su - root Let us consider the file as below, in which I have to comment ...
5
votes
3answers
186 views

Extracting data from complex file structure

I have a txt file that is a dump from a database, that contains one entry per line. The structure is like this: 1500 29/03/2010 18 02 09 47 17 45 28.248 0 0.01 130 12.721 7908 298,809 YES ...
0
votes
0answers
24 views

Replacing code between two JavaScript comments

I need to set a value of JavaScript variable from bash. Variable lives in index.html file and I'd like to use unix SED command to do that. Inside index.html I have it lake this: <script> ...
1
vote
4answers
1k views

Convert all text from uppercase to lowercase and vice versa?

My question is how can I convert all text from uppercase to lowercase and vice versa? That is to change the cases of all the letters. It has to be done with a sed replacement somehow.
0
votes
1answer
26 views

How to escape unbalanced brackets or slash in sed?

I'm trying to use sed, but my pattern contains [] brackets and slashes (/). I've tried quotes, but it doesn't help. How do I escape it? Examples: $ sed -i'.bak' "s/^includes[] =/;includes[] ...