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

learn more… | top users | synonyms

0
votes
3answers
67 views

Concat 1000 files within a directory [on hold]

I know we can concat files by cat file [file] [[file] ...] > joined-file. I have directory which contains lots of files. I want to concat all of them. I want to concat 1000 files irrespective of ...
-1
votes
0answers
34 views

How to merge these three task in a single command ( grep | sed | echo)

I am trying something where I parse out from the tags in a file then add back the HTML. I see everyone suggest not to do such with regEx (grep). but here it is grep -m 1 -oP ...
0
votes
3answers
39 views

awk or sed or perl: remove only characters on specific position

I have multiple files to rename leng-1494-001 leng-1464-002 leng-2414-004 leng-7894-005 leng-1323-006 I want to rename it ferr-1494-001 ferr-1464-002 ferr-2414-004 ...
0
votes
2answers
58 views

Print text between two patterns not containing a particular word

I wanted to print some text between two patterns which doesn't contain a particular word input text is HEADER asdf asd asd COW assd TAIL sdfsdfs HEADER asdf asd sdfsd DOG sdfsdfsdf TAIL sdfsdfs ...
2
votes
1answer
42 views

How do I properly escape this long su + sed command?

#!/bin/bash wineuser=tom su $wineuser -c "sed -i '$ialias ptgui "wine ~/.wine/drive_c/Program\ Files/PTGui/PTGui.exe\"' /usr/people/$wineuser/config/cshrc.csh" The acutal line inserted to tom's ...
0
votes
2answers
46 views

delete lines of a file from a file

I have about 14k lines to delete from a file. They are in another file: $ cat delete.lineno.txt 12d 23d 24d 78d ... .. etc. I need to delete lines 12, 23,24,78 etc from a file say my.file.txt. How ...
2
votes
1answer
24 views

Adding consecutive characters to duplicate words according to order they appear

So I have files like this but for hundreds of different genes per file. >lcl|accession_cds_proteinaccession [gene=dnaA] [protein=description] [protein_id=accession] [location=location] ...
3
votes
3answers
229 views

Extracting unique piece of text from file with awk, sed or grep

From the output of pactl list sink-inputs, I need to grab the sink input number for VLC. Before that, I'm trying to extract the piece that contains the output for only VLC. All the methods that I ...
1
vote
2answers
53 views

How to do operation on individual matches in a full line

I have a Verilog line like this: if (i2_0&!(i2_1)) (posedge i0_0 => (o:1'b1))=(0, 0); How can I convert it to a line like: if (i2_0 == 1'b1 & i2_1 == 1'b0) (posedge i0_0 => (o:1'b1))=(0, 0); ...
2
votes
4answers
143 views

Column editing using awk or sed. how to print the following pattern?

Sample Input: title role subject name-JOHN student math school state NY county street Phone name-TOM student math school ...
0
votes
2answers
44 views

Delete customers domain extension only (in .csv file)

I have a list of my customers emails and want to remove some that end in .br for example. I would normally do the following command: sed -i '/.br/d' customers.csv But that would also delete a ...
2
votes
2answers
36 views

sed - print and branch

I have an input stream containing strings representing file types. I want to print all file types that are not text or are PostScript (PostScript is a text file type). I tried the following sed ...
2
votes
1answer
186 views

Perl /Sed replacement

Below command is used to replace the password in a script but the perl command is adding a white space when it does the subsstitution password=arche20 perl -i -p -e "s/^(password[]*=[ ]*).*$/\1 ...
0
votes
2answers
38 views

.csv Keep only certain email addresses?

I have a large .csv file with my customers Name:Email I have another large list of emails that are part of this list and only want to keep those. How can I remove all contacts from the .csv file that ...
0
votes
3answers
30 views

How to match and replace an attribute value inside a tag

I am trying to replace the value of following node using sed command. <KeyValue key="EMPTY_SEARCH_CRITERIA" type="String" value="CS_CODE" comment="Configured empty search criteria."/> I am ...
0
votes
3answers
38 views

How can I add a line including single quotes to a file with sed [duplicate]

I want to append the following line to a text file with sed: gem 'forum2discourse' I've tried sed -i '$a gem \'forum2discourse\'' Gemfile but this drops me to a > prompt so I think I must be ...
0
votes
1answer
46 views

Cutting logs (and not copying) from a log file between two time stamps

I have a very huge access.log file of 2 Gb containing apache access logs. The date time format in that is as below : 04/May/2015:02:15:25 I want to cut (and not just copy) the logs from this ...
1
vote
3answers
45 views

How to use sed or awk to obtain just a directory

3:ââsdb1 8:17 1 984M 0 part /media/(NAMEOFDRIVEHERE) I want to just have the /media/(NAMEOFDRIVEHERE) location so I can store it in a variable. I've tried some sed commands and have ...
1
vote
2answers
35 views

Add string to list using either AWK or SED?

Hi I want to be able to edit the list of name like this using either AWK or SED. Sample input list file: john paul rose lily Desired output: I am john of earth; I am paul of earth; I am rose of ...
0
votes
0answers
35 views

Using sed to unlock fields in a pdf

At my job we regularly unlock the fields of pdf files in order to edit them using this sed script in a .bat file: type %1 | sed -E 's/(.*\/T\([a-zA-Z0-9]*\).*)\/Ff 1(\/?.*)/\1\/Ff 0\2/' | sed ...
0
votes
1answer
31 views

How to replace multiple occurrences of a pattern with sed

I use the following command to remove surrounding spaces between array keys that are strings or integers in PHP files: sed -ri "s/\[ ([0-9]+|(\x27|\x22).*(\x27|\x22)) \]/[\1]/g" file.php I thought I ...
6
votes
1answer
135 views

Why can't I escape the braces “]” in sed?

Question: Why can't I escape the "]"? $ printf "*#$@~\!&*()[]\n" *#~\!&*()[] $ printf "*#$@~\!&*()[]\n" | sed 's/[*#$@~!&*()\[\]]//g' *#~\!&*() $
3
votes
1answer
45 views

Counting number of entries in column 2 where column 1 is similar

I am trying to count the number of entries in column 2 for the same column1 and also number of times the first entry in column2 for similar column1 occur. For example my input TSV file is: C1 NC01 ...
2
votes
4answers
71 views

Adding File Text With Sed

#!/bin/bash search_string="\/sbin\/iptables -A INPUT -p tcp --dport 12443 -j ACCEPT"; delimeters=$(cat /root/firewall/firewall.txt); sed -i "s/$search_string/$delimeters$search_string/" ...
0
votes
1answer
35 views

Use sed to only replace namespace in an element that has a parent element with a given attribute value

I want to replace the namespace in an xml file using sed (I've given up trying to do it from ant, where it is required). The main issue is that that there is a repeating list of elements - not all of ...
1
vote
1answer
34 views

Conditional awk across 4 columns

I have a tab-delimited file with 9 columns as follows: 1 25555818 T 14 0 0 0 14 0:0:0:14 2 25555819 T 14 7 0 0 7 7:0:0:7 3 25555820 G 13 0 0 13 0 ...
0
votes
3answers
39 views

How to remove a string of characters after and before a specific character?

I have a file with thousands of lines that start with: >Miriam132_38138 Otu32555|1 I need to remove 'Miriam*********' so that each lines begins with: >Otu32555|1 The first string of ...
0
votes
1answer
20 views

sed escape /var/run/saslauthd [duplicate]

I want to remove this line from fstab using sed: /var/run/saslauthd /export/sasl none bind 0 0 I know a workaround, first give the number of line, then remove it with sed, but I want to know how to ...
1
vote
3answers
37 views

How can I swap the order of each two character pair in a string?

I am trying to automate the swapping of characters 1 and 2, 3 and 4, etc, in a an arbitrary-length string of hex characters. Example: A627E39B becomes: 6A723EB9 It seems like this should be ...
2
votes
2answers
41 views

Replace between patterns that start and end in different lines

I have a file with the following format: Whatever1 Whatever2 Whatever3 binaries=( text1 bin2 ohhh3 ) Whatever4 Whatever5 Whatever6 I need to replace whatever inside lines binaries=( and ) with a ...
0
votes
2answers
36 views

use i option to add text as the first item on a line

I need to add a word before the line starts, but I want to do that for every line which the text has. If I have sample/text/ and I want to add data/sample/txt, how can I do that? I have tried sed i ...
3
votes
4answers
204 views

How to truncate the second column to given length

Given input of the form XY981743 foobarlkasdf saflkas asfZR!sgfad asdSAD asdsadf SAdfasdf46lk lksad bar foolkasjfdrte how can I truncate only the second column? The delimiter is TAB and the ...
2
votes
1answer
61 views

How to replace “&” with “&amp;” except when already part of an XML entity?

I have a file (xml) with many &amp;/&lt;/&gt;/etc, but sometimes also some & characters by themselves. I want to change this symbol to &amp; without replacing the others. cat ...
0
votes
3answers
58 views

Printing column value in the next line

My input is in TSV format: C1 r1 r2 r3 C2 r1 r3 Desired output is: C1 r1 r2 r3 C2 r1 r3 So, basically what I want is printing value of column 1 in next line, is it ...
5
votes
6answers
299 views

split file into two parts, at a pattern

How to split a large file into two parts, at a pattern? Given an example file.txt: ABC EFG XYZ HIJ KNL I want to split this file at XYZ such that file1 contains lines up-to XYZ and rest of the ...
1
vote
1answer
57 views

Using sed to replace a string with special chars with another string with special characters

I'm trying to automate switching out a bash prompt for another in .bashrc Original String: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' ...
2
votes
3answers
49 views

Reformat date string

I am trying to figure out how to reformat a file full of wrongly formatted dates. The source looks like this: {"_id":"","timestamp":"Mon Apr 20 08:30:55 +0000 2015"} {"_id":"","timestamp":"Mon Apr 20 ...
7
votes
3answers
137 views

How to use [\w]+ in regular expression in sed?

I am on Windows, but I guess my question is still rightly placed here. C:\Users\User>grep --version GNU grep 2.6.3 C:\Users\User>sed --version GNU sed version 4.2.1 I noticed that the ...
1
vote
2answers
32 views

Using Unix, when detecting a pattern, we need to detect its corresponding other pattern

When detecting the line containing the pattern night, we need to detect its corresponding line containing the other pattern === which is just occurring at a higher line as shown below. File content: ...
1
vote
2answers
45 views

Delete text from a file using regular expressions

I have lots of text in a file. I want to delete all text that are between symbols === and <!!!>. E.g. Text ===some comments<!!!> lala ===aaa<!!!>" should be Text lala after running ...
1
vote
2answers
65 views

Search and replace multiple strings in a script using vim(search and replace) commands without sed?

A script that creates a file for weather precipitation is, #!/bin/ksh x=10 b=snow c=rain d=snow e=hail echo "$x,$b,$c,$d,$e" > weatherfile exit 0 given 3,8s/snow/dry/g For the search and ...
0
votes
3answers
41 views

What characters should I escape while modifying a file using sed? [duplicate]

I am using the following sed command(with word boundary): sed "7 s/\<<Filevalue=.*/>\>/<Filevalue="true"/>/" < config.xml And I am getting this error: sed: command garbled: 7 ...
1
vote
2answers
108 views

sed: problem while replacing string using wildcard

I am trying to replace a string using the following command: sed -e "s/\<$5\>/$6/g" "$2/$1" > "$4/$3" $5-> "hostname=*" $6-> "hostname=int1" $2/$1-> "source file path" $4/$3-> ...
0
votes
3answers
31 views

Vim replace in a visual mode

In a block of test like this cron.allow cron.deny I want to substitute cron with at,only in the range selcted by visual mode(ctrl+v) So i press ctrl+v : and appear the ! prompt ok I do sed ...
0
votes
1answer
55 views

Help in manipulating a test file

I have a file look like aaa/bbb/ccc.bbb aaa/bbb/ddd.bbb aaa/eee/fff.eee aaa/eee/ggg.eee I would like to skip lines ending similarly (where ending is defined by the extension, e.g. .bbb & .bbb) ...
5
votes
1answer
180 views

Replace non-printable characters in perl and sed

I need to replace some non-printable characters with spaces in file. Specifically, all characters from 0x00 up to 0x1F, except 0x09 (TAB), 0x0A (new line), 0x0D (CR) Up until now, I just needed to ...
0
votes
3answers
45 views

Read line from file and add that to the same line of another file

I have one file like this: aaa bbbb c And another one like this: 1 1241 2 301094209 3 432423 I want this: 1 1241 aaa 2 301094209 bbbb 3 432423 c so I can plot it with Gnuplot. If you ...
0
votes
2answers
47 views

Using sed, add line X lines above match

I know that to prepend/append something, I just have to do: sed -i '/pattern/a new thing!' However, I'd like to match a line, and prepend something two lines higher. I'd like to limit tools only ...
0
votes
2answers
41 views

Order the output using sed [duplicate]

I need your help using sed. I have this output after executing diff: < #R1#Number = Gauge32: 258 Name = STRING: "TATA" --- > #R1#Number = Gauge32: 280 Name = STRING: "TATA" I need to ...
-1
votes
2answers
32 views

Extracting certain data within a script output file

We have a script that runs several commands and rolls up all the output and inserts in into a log file. One of the commands it runs is "netstat -anp". I'd like to be able to search this file for all ...