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

learn more… | top users | synonyms

1
vote
3answers
183 views

Replace specified character between two strings?

i have something to accomplish. i need to replace all occurrence of & inside or between <ex> </ex> to #. actual example below: a & b & c <ex> a & b & c ...
2
votes
5answers
306 views

Remove multiple lines after a pattern match but only after pattern match

I am trying to remove all instances of a pattern match from a file if it matches a pattern. If there is a match, the (complete) line with the matching pattern and the next line get removed. The next ...
0
votes
1answer
46 views

Is there a way to create a new file and insert text into this file all with bash? [closed]

I need to change and create several configuration files for some kiosks at work, is there a way to do this with a single bash script? I've heard about SED but the documentation is confusing, could ...
1
vote
3answers
36 views

Concatenate Sequences under a Heading

I have a file like File1. With a heading for example ">Contig1" and I want to concatenate all the sequences under the respective heading. File1: >Contig1 ACCCCATACATCCAAA NNNNNNNNNNCATACA ...
0
votes
5answers
114 views

print only rows that has latest non empty cell that starts with the word “Failed” on a CSV file in Linux [closed]

I want to print the table only if non-empty latest column that starts with the word "Failed"on a CSV file in Linux.. My input - Name,Mon,Tue,Wed,Thu,Fri,Mon Linux,Successfull Fullbackup; Failed ...
1
vote
1answer
129 views

Pattern replacement

Please can anyone explain to me in brief the syntax of this command. Explanation in terms of how actually this command is written significance of each and every character used. I know the output of ...
2
votes
4answers
100 views

sed load substitute from file

I'm attempting to replace a pattern in a file with the complete contents of another file using sed. Currently I am using: sed "s/PATTERN/`cat replacement.txt`/g" "openfile.txt" > "output.txt" ...
3
votes
1answer
53 views

Using sed to replace only the first two regex catches with different strings

So I'm trying to change two instances of a regex pattern to two different strings with sed like: sed -E "s/\\t([A-Za-z]|[-])+$/\\t`get_addr.py -1`/" /path/to/file.ext sed -E ...
3
votes
3answers
50 views

Removal of lines with more than 'N' fields?

I am working on mac with sed, perl, awk, bash.. I have a large-ish (10GB) text file which has 13 fields (columns) of TAB delimited data. Unfortunately some of these lines have extraneous TABs , so I ...
8
votes
7answers
387 views

How can I “merge” patterns in a single line?

I am doing grep and sed and I get 2 lines of a file that I am interested in. How can I get these lines in a single line ending with the new line character? Now I am getting: pattern1 pattern2 ...
0
votes
1answer
72 views

Add text to end of every line

I have tried a lot of commands, like this: sed -i '' "s/$/<@string>/" txt.txt > txt2.txt This makes txt2.txt empty, why?!? sed 's/$/<@string>/' txt.txt > txt2.txt This does ...
-1
votes
1answer
26 views

How do I change the Old Directory path to New Directory path using SED command

I have the old path it contains the some files. /home/ubuntu/Desktop/test-dir Now I want to change the test-dir to new-test-dir directory. /home/ubuntu/Desktop/new-test-dir How do I change ...
1
vote
2answers
47 views

How can I replace ^I into tab spaces in vim editor for .java file?

When I open my .java file in vim, I could see a couple of lines prefixed with one / more ^I characters. It looks like tabs in Eclipse that has got converted into ^I. I would like to replace a single ...
3
votes
3answers
131 views

Parse multiple sections of data into seperate files

I have a concatenated log file with multiple logs inside that I'm trying to parse out into individual log files (I will later rename them to the date/time of each). Each log is separated by "--- LOG ...
3
votes
4answers
104 views

How to remove text matching specific patterns from a file

I want to compare two files to check for differences between them, fileA and fileB. fileA is like a template file and fileB is the file which I want to compare to it. Anytime I find a difference I ...
2
votes
2answers
71 views

Replace a backslash with sed

I've been trying to create a script that would replace every occurence of C:\ in two different types of file by /root. My arborescence looks like : - Batch - Place of the script - Conf - Appli1 ...
3
votes
2answers
303 views

Get text between a word and the last line?

According to the answers in Stack Overflow question How to use sed/grep to extract text between two words?, we can get text between two words: sed -n "/first/,/second/p" file But what if I want to ...
3
votes
3answers
139 views

Nexenta bash script uses /usr/sun/bin/sed instead of /usr/bin/sed

I'm using a script for Linux and for Solaris (Nexenta). This line works on Linux, but not on solaris (but when run from shell it works): cat "pg_hba.conf" | sed "0,/^local/{s/md5/trust/}" The ...
2
votes
3answers
50 views

sed whitespace matching confusion

echo ' 1 2 3 '|sed 's/[[:space:]]*/_/g' I want to see _1_2_____3__ as the output. Instead, I am seeing _1_2_3_ as the output. What am I doing wrong?? EDIT The other thing confusing me, which I ...
0
votes
1answer
40 views

Quote escaping struggle with grep and sed

I'm writing a bash script to extract data from html tags and I found this command in another thread : grep -o '<tr>.*</tr>' HTMLFILE | sed 's/\(<tr>\|<\/tr>\)//g' > NEWFILE, ...
-4
votes
1answer
95 views

What command in bash to search for this string?

file.txt contains: aa=testing sss=whoiam bbb=findme What command do I use to search for testing and print it? Expected result: # you search testing
-2
votes
3answers
62 views

How to sed two same value without affecting the other

I have an xml file and I want to change one value on that file: param name=swam_license_ports_overdraft_thresh 99 param name="strike_license_ports_overdraft_thresh" 99 The outcome I want is to ...
1
vote
2answers
109 views

Vim: join lines by replacing ^M

I have a file which has embedded ^M characters. I wish to join the lines at the ^M character. ie: change this: ^M être, ^M étant, ^M ...
2
votes
3answers
238 views

How to add a new line after the “test message1” using sed?

Actually I have a file called test1.txt. In that file I have the following five lines: 'test message1' 'test message2' 'test message3' 'test message4' 'test message5' Now I want to add a new ...
0
votes
5answers
56 views

re-arrange values in one column without affecting other columns using awk or sed

I have a csv file in following format: abc,124,123,2014-08-13,abc def,124,123,2014-08-13,abc ghi,124,123,2014-08-13,abc Now I need to modify only 5th column (2014-08-13) to produce output as given ...
2
votes
1answer
39 views

Move matched line above a different matched line using sed

I have something like dsadjakldjska safdsfdsfsf fdsfsf**STGN**fdsfsd fdsfkjldsf fdsff fdsfs**IRV**fdsfs and I want to get dsadjakldjska safdsfdsfsf fdsfkjldsf fdsff fdsfsf**STGN**fdsfsd ...
0
votes
2answers
100 views

Delete every number that comes before “=”

i have a very, very, very long list. Like over 830,000 characters. I will of course perform said command on a copy. There are multiple lines, like this hey1=lol hey2=lol hey3=lol I want that to ...
1
vote
1answer
57 views

Handling sed variables with paths in them?

I have an applescript for doing certain things, like search and replace. set lol to quoted form of POSIX path of (choose file with prompt "VälJ Fil") That chooses a file then im doing this set ...
3
votes
5answers
339 views

How to use a shell variable inside sed's s command? [duplicate]

we know that we can get the value of a variable using $ sign: x=3 echo $x 3 Is there other ways that we can use to get the value without using $ sign. I'm asking this because $ sign is a special ...
2
votes
3answers
120 views

Replace a word after a significant line and white spaces (inline) using sed?

I have the following text: A Hello world B Hello world C Hello world I know that I can replace Hello by Hi using sed: sed 's/Hello/Hi/g' -i test but this replace each Hello ...
2
votes
3answers
34 views

Delete until given character starting from given string

root@server:~/foo$ cat INPUT.txt limit. Current u'^'ZO limit. Current usage'^'FR limit. Current us'^'AS limit. Current usage 95 %.'^'FR limit. Cur'^'AEW root@server:~/foo$ sed ...
4
votes
1answer
164 views

Using sed command convert only first character in specific line with uppercase

How can I convert the first character of each word in the line after gr-description: to uppercase? For example : $ cat /tmp/test1 groMail: test@xyz.com gr-description: abc-location-999 ...
1
vote
2answers
57 views

Delete all words surrounded by parentheses with sed

How can I do this in sed, I have a long long list of things and some are surrounded by a parentheses. lol xml lol lol (347) idiot (67) How can delete (347) and (67) but for a huge list with numbers ...
0
votes
1answer
67 views

Print lines if pattern is not matched

Print lines of File 1 only if they don't contain patterns specified in File 2 Exemple: $ cat File_1 L1 pattern1 L2 pattern pattern2 L3 pattern3 pattern L4 pattern4 $ cat File_2 ...
0
votes
2answers
123 views

Rearrange the file content

I have a file with content as 123 OneTwoThree 234 TwoThreeFour 345 ThreeFourFive I want to convert this file into something like this OneTwoThree 123 TwoThreeFour 234 ThreeFourFive 345 Here ...
7
votes
0answers
133 views

regarding portable sed -e… d b or ! b?

In this edit Stéphane Chazelas POSIXifies (again) my sed formatting by inserting an -expression break and another -expression statement. Now, I might just ask him why in the comments, I suppose, but ...
2
votes
2answers
232 views

Replace value within single quotes in a line that contains certain word using sed command

I have a line as below in a html file, shahar.push(['remoteUrl', 'staging.zazzercode.com']); Depending upon environment, I want to replace the remoteUrl value with sed command. eg, ...
5
votes
4answers
223 views

How to replace m part of Lines with n part of Lines?

I have a file "test" like this: RewiteEngine On RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.7$ [NC] RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.8$ [NC] RewriteCond %{REMOTE_ADDR} ...
5
votes
3answers
217 views

sed ranges aren't always able to match only one line

Consider the following range: 1,/pattern/. If pattern matches on the first line, the range matches for the whole file: $ cat 1.sh #!/usr/bin/env bash set -eu seq 1 4 | sed -rn '1,/'"$1"'/p' $ ./1.sh ...
1
vote
1answer
42 views

Why does sed globally substitute only the first occurence in multiple substiutions?

I want to globally substitute all \n new line characters with their \n escape sequence and all ' single quote characters with two '' of them like so: function esc_foobar { # Escapes any "'" ...
3
votes
1answer
57 views

grep upto matching brackets

I have a file like this:- pin(ABC) { a b c d e f { abc } } pin(XYZ) { g h i j k { j k { ...
1
vote
2answers
76 views

rename a batch of files after reading from a source file

I have a directory full of over a thousand files and the names are bit long (and no pattern found in the naming style). I would like to simplify the filenames. E.g.: ...
0
votes
1answer
112 views

Why does this command not work on AIX?

I want to remove UTF-8 BOM from a file using this command: sed '1 s/\xEF\xBB\xBF//' old.java > tmp.java But it did not work. I am running with ksh on AIX 7.1
1
vote
2answers
64 views

How can I sort a .txt file by two columns?

Feb 7 domainserver dovecot[37495]: auth(default): od(tjones): lookup failed for user: tjones Above is a sample output of what I'd like to sort. I'd like to sort by date on the first column, but ...
3
votes
1answer
164 views

How to export data in the terminal to a file (e.g. csv file)

I am a complete beginner in using Linux and I would like to know how to export a bunch of data in the command line to a csv or spreadsheet file (or even text would work). Right now I am simply using ...
0
votes
1answer
86 views

grepping of common lines between two file based on specific columns values in case of multi matching

I want to match column3 of file1 & column2 of file2 , after that i want to print all column of matching lines in a single line, i know how to do it but the problem is that if there are not unique ...
1
vote
2answers
108 views

replace lines in a text with matching text

Original file 123|abc|heloo good morning friends|1|123|abc|123|abc 123|abc|heloo good morning everyone|1|123|abc|123|abc Replaced file 123|abc|heloo good morning freinds|1|123|abc|123|abc ...
1
vote
2answers
625 views

Using sed to replace characters between two patterns

I'd like to replace all the newlines after a line containing a given pattern with a tab. Input file: $ cat File1 NAME1 N1_info NAME2 N2_info I'm creating some flags at the ends of the future ...
0
votes
2answers
252 views

how to remove all double quotes from csv except specific field

I want to remove all double quotes from my csv but not the fourth field (because the four fields represent PATH of file) Please advice how to implement this by sed or awk or perl one liner , etc ...
2
votes
2answers
225 views

Replacing lines containing a pattern with sed

How can I replace a given character in a line matching a pattern with sed? For example: I'd like to match every line beginning with a letter, and replace the newline at the end with a tab. I'm trying ...