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

learn more… | top users | synonyms

-1
votes
2answers
36 views

Need help in removing XML Tags with empty properties

Input File: <ServiceArea type="STATE" value="DC"> <DaylightSavingsUsed value="true"/> <FemtoSipProxyAddress value="10.13.123.100"/> <TermAuthAAAPSK value="secret1"/&...
3
votes
2answers
84 views

Replace only in particular range string

In the canonical How can I replace a string in a file(s)? in 3. Replace only if the string is found in a certain context, I'm trying to implement the replace of a pipe with white spaces in file with ...
0
votes
3answers
103 views

Print start and end between two patterns excluding end of range [duplicate]

I want to use sed -n "/START PATTERN/,/END PATTERN/p" file.txt pattern to search in a file. file.txt content is ~keyword~, ~output~. ~1.~ ~output~. ~2.~ ~output~. ~keyword~, ~output~. ~1.~ ~output~. ...
4
votes
3answers
109 views

Replace multiple lines with a string when the line numbers are stored in a file

I have a file with few million lines, all the same. just for an example: Known Known Known Known Known Known ... I have another file with few thousand line numbers, for an example: 3 5 6 ... I ...
0
votes
1answer
35 views

How can i remove duplicates from the output of tshark output [duplicate]

sudo tshark -i ppp0 'tcp port 80 \ and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' \ -R'http.request.method == "GET" && http.request.uri contains "/ABC/...
0
votes
1answer
33 views

I would like to erase the previous point of the multiple lines of text

I would like to erase the point of beginning point , as shown below. The name of the file aaa.txt. ./usr/share/vim/vim73/colors/blue.vim ./usr/share/vim/vim73/colors/default.vim ./usr/share/vim/...
0
votes
2answers
51 views

Help in making multiple lines as single lines

I have below 4 lines: EXTRACT ETEST Last Started 2016-03-20 20:56 Status RUNNING Checkpoint Lag 00:00:02 (updated 00:00:04 ago) EXTRACT PTEST Initialized 2016-03-31 06:25 Status ...
2
votes
3answers
38 views

`pwd`, but omit first n directories

pwd gives the full path of the current directory, for example: /first/second/third/anotherdir/thefinaldirectory How can I omit the first n, let's say three directories, so that only /anotherdir/...
1
vote
3answers
35 views

Remove front-slash using sed

I have a text file that contains following https://git.centos.org/git/rpms/abc.git https://git.centos.org/git/rpms/abc.git/ https://git.centos.org/git/rpms/abc When I run the following command, ...
0
votes
1answer
56 views

sed cannot insert if a file ends with empty line

I have a file uca.xml (Thunar configuration for custom actions): <?xml encoding="UTF-8" version="1.0"?> <actions> <action> <!--some code--> </action> </actions>...
0
votes
1answer
52 views

How to compare the strings using < (Greater than symbol)

Below is my input file: PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:16:46.523.177, 2 PS Sensor Value = -5.501000 , Min = -5.583000 , Max = -5.319000 PA43410-2,1,3,/vobs/...
3
votes
1answer
135 views

how to use awk to do subtraction with numbers in a large file

I have a large file like this AT5G44030,TAACARA,1000,+,200,206 AT5G44030,TAACARA,1000,+,418,424 AT5G44030,TAACARA,1000,+,773,779 AT5G44030,NGATT,1000,+,114,118 AT5G44030,NGATT,1000,+,267,271 ............
1
vote
3answers
66 views

sed delete all besides first and last line of many files

I'd like to process many *.txt files in a directory - they have a common structure (; separated, common headers) but vary in the number of lines each is comprised of i.e. some are just a single line, ...
1
vote
2answers
49 views

SED Search and Replace on Linux [duplicate]

I want to change the value from 1521 to 1525 in FROM_HOST only in file gexhosts.cat: FROM_HOST db201521 TO_HOST db201521 Is there a way to do that or some work around? I would really prefer ...
0
votes
0answers
9 views

how to replace a string in vcf file which have a common charecter? [duplicate]

I want to replace any string which have the common charecter. like any string which have 1/1 in it will be completely replaced by "heteroV!" I have tried this command sed -iBAK2 's_\(1/1:[0-9]\+:[0-...
0
votes
2answers
103 views

Curl and Grep to Parsing Content

I need to parse the output of a curl command: curl --user test:test http://192.168.1.1/security/pkm.html | egrep '@company|config.pkm.password' This returns: <input type="text" id="config.pkm....
0
votes
3answers
32 views

Perform regex search on a previously regex-matched line (one-liner)

I need to print a string which is in a unique line in a long text file. Example relevant line in file long.txt: Software version 4.0.10, 2002-03-28 The wanted string is exactly 4.0.10. The steps ...
0
votes
1answer
69 views

bash script to replace server short names in a file with fqdn

I have a rather large config file that has server short names in it like this: [host 1] host = server1 [host 2] host = server2 [host 3] host = server3 I need to replace all the server short names ...
-1
votes
1answer
75 views

Sed in httpd.conf only for only one <VirtualHost>

I have a httpd.conf file containing the following virtual hosts : <VirtualHost *:443> JkMount /soncn/* tomcat3 SSLProtocol -all +TLSv1 SSLCipherSuite RSA:!LOW:!EXP:!eNULL:!aNULL:!RC4 SSLEngine ...
0
votes
1answer
44 views

Deleting multiple lines of HTML comment using sed

This is what I came up with but it doesn't work with multiple lines: sed -i '/<!-- my comment -->.*<!-- \/my comment end -->/d' my_file
1
vote
5answers
183 views

How to print nth line after match / empty lines

I'm trying to write a short script that finds empty lines and then prints the nth line after the empty lines. For foo1 foo2 foo3 bar1 bar2 bar3 spam1 spam2 spam3 eggs1 eggs2 eggs3 printing ...
0
votes
1answer
33 views

replace inside a file with some specific structure

I have a file look like: login1.stampede(73)$ cat mc_input 800 ! n_pass 300 ! n_equil_pass 6 6 6 ! simulation cell dimension in x, y, and z 700 ! Tinit 100 ! Tmin 700 ! Tmax -10 ! Tinc Li -...
0
votes
1answer
33 views

How to catch everything after prefix phrase with SED?

How to catch everything after prefix phrase with sed? Like here I wished to catch active/idle: $ sudo hdparm -C /dev/sda /dev/sda: drive state is: active/idle $ sudo hdparm -C /dev/sda | sed "s/\...
2
votes
1answer
64 views

find and replace a string in a file without using temp file with SED

I have a text file called sample.text which looks like this Continent Lat/Lon: 46.07305 / -100.546 Country Lat/Lon: 38 / -98 City Lat/Lon:(37.3845) / (-122.0881) I want to process this text to get ...
2
votes
1answer
36 views

using Sed to find and replace a string inside a file [closed]

I have been trying to replace '{{date}}' with a current date stamp in OSX command line. I have been using the following: sed -i -e 's/{{date}}/`date`/g' mhp.xml Does anyone know why it ends up ...
0
votes
0answers
30 views

How to add time stamp(month_year) to the file after matching specific string?

I want to add time stamp inside the file only after matching specific string, time stamp format: 03_2016 file contains "$channel_name Policy" string, I want to replace this string with "$...
1
vote
1answer
26 views

How to replace a word in a file by a word get by read function? [duplicate]

Situation: echo "tell me a word" read the_word How to replace all WordToReplace in a file by the_word? sed does not seems to appreciate: sed -i 's/WordToReplace/$the_word/g' thefile.sh
1
vote
1answer
38 views

Remove lines that contain file path using sed

I have a list of lines in a file that look like this: 6642a51e0ed5e6f89e5e4090b9aa0fb3 /home/device/eth0/uid d66d1417251a9a151176c34acf046878 /home/device/eth0/uid64 ...
0
votes
2answers
56 views

Sed: Look for IP Address between range?

How does one look for a range in IP Addresses with sed? For example: sed '/85.159.56/s/$/ --- API SYSTEMS/' This would locate IP Addresses starting with: 85.159.56 and print next to it: --- API ...
0
votes
1answer
45 views

Removing new line characters around patterns

I have a fasta file of millions of paired sequences, that looks like this: >7001289F:56:HKH3FBCXX:2:1101:1692:2074 1:N:0:CGATGT ...
0
votes
2answers
63 views

How to get only certain fields from a given file?

I have list of employees in following format Name: Phone No: Email: Name: Address: Phone No: Email: Name: Country: Address: Phone No: Email: Name: Address: Name : Email: Address: All I want ...
3
votes
2answers
57 views

sed pattern and multiline substitution

I need to parse a text file and replace a certain portion of it. I believe sed is the way to do it but not sure how to handle multiple lines with it The pattern I am looking is set cells { \ cell1 ...
-1
votes
1answer
45 views

Understanding operators using sed

Trying to understand and break down this command. echo -e '1234\n4567' | sed 's/^\(..\)\(..\)$/\1:\2/' Being a novice with shell and sed I'm at a loss where to start in breaking down various ...
1
vote
2answers
109 views

Find files containing a set of words

I'm using grep to find files within a directory, containing a set of words. But grep search lines containing these words, what I want is grep to show me the files or file containing all those words ...
1
vote
1answer
58 views

Extract random sample of N lines based on pattern

I have a file formatted like this: train/t/temple/east_asia/00000025.jpg 94 train/t/temple/east_asia/00000865.jpg 94 ... train/s/swamp/00000560.jpg 92 train/s/swamp/00000935.jpg 92 .... train/m/...
2
votes
2answers
26 views

How to append a string to the first column of a matrix file?

I have a matrix file as follows. The first column is a name list. I want to add _i1 to the end of each name. A1A A1B A1C A1D A1E TR6764_c0_g2 0.00 0.02 0.00 0.00 0.00 ...
4
votes
4answers
129 views

Replace strings in a file based on a list of strings and a list of corresponding replacements

I am trying to replace strings in a file A: Hello Peter, how is your dad? where is mom? where the strings to be replaced are in file B: Peter dad mom and their corresponding replacements are in ...
0
votes
2answers
36 views

Error in yaml - possibly due to wrong escape, but unable to identify the issue

The line below causes an error (...request body malformed."}). It is part of a user-data.yml for use with cloud-init as part of the digital ocean api to bootstrap a server upon creation. sed -ie '\$a\...
0
votes
1answer
34 views

Remove tab, new line, carriage return until encountered char

I have a CSV file that has record separator of ,\n. One of the columns, has the possibility of containing tabs and new lines, which I wish to remove. How do I remove these chars (\t\n\r) using sed and/...
2
votes
0answers
56 views

Awk /sed extract information when a pattern match from a paragraph

I want to search a pattern "FROM" in paragraph that begins with CREATE VIEW and ends with ";" and save the result in a csv file. for example if I have the following file : CREATE VIEW view1 AS ...
3
votes
1answer
42 views

Get contents of a file from first instance to last instance of some arbitrary string

How can I view in less from the first instance of some arbitrary string "foo" to the last instance? This arbitrary string will be on most every line of the log. I don't want to do grep "foo" bar.log |...
1
vote
1answer
40 views

Sed delete line if nth character is not specific character

I have a csv file, and I want to delete lines if their 12th character is not ;. So, for example, my file looks like this: 2266308;A;B;dfsgsfdg 2266309;A;BJHSADFK;gfsdg 2266310;A;B;dfg and I ...
0
votes
3answers
40 views

remove sequential lines that begins with the same pattern using awk or sed

I want to remove the sequential lines that begins with the same pattern "CREATE CURRENT" using sed or awk for example if have the folowwing file: CREATE CURRENT = 'aaaa' ; CREATE CURRENT = 'bbbb' ; ...
0
votes
2answers
50 views

insert complex line before or after complex line

i have file with complex text print("ERROR: passwords don't match") password = hash_func(password.encode("UTF-8")).hexdigest() i need to insert this text between them with open('/etc/openvpn/...
1
vote
3answers
45 views

Count occurance of number and delete line of matches value

Could I get some help please with my problem? I have a file that looks like this (comma separated): A,250,13,820,0,80,201 B,0,0,0,0,3,0 C,0,2,1,0,0,0 D,0,1,105,0,0,10 I would like to ...
0
votes
2answers
55 views

using sed to modify all files in a directory and name the outputs accordingly

I want the sed command to work on all files in a directory and output the result into a new file. If f is val1.txt, the name of the output file should be val1_ended.txt -this is what I am trying to do ...
0
votes
2answers
35 views

sed to change dns log string format

I want to use sed to change the following text: (3)www(5)first(3)nth(6)domain(3)com(0) to: www.first.nth.domain.com Can each group between the parenthesis separators be captured and then ...
1
vote
3answers
74 views

How to do following formatting using sed or awk or bash script on linux

Suppose, I have two files: file1 having below contents. message_aaa.wav test 1 of 1 test Label : aaa test Sentence : test aaa test String: test message Interpretation ...
1
vote
2answers
39 views

Sed from line 6 on from all txt files and being able to output all the results in a single file

I need to sed from all *.txt files from line 6 until the end All the results should be in a new single file with the name of each file preceding the results Example: Having different txt files the ...
0
votes
2answers
54 views

using awk to unzip files in directory

I have some zip files in directory when I need to unzip each in specific dir I used ls | awk '{ print "unzip " $1 " -d " $1} ' unzip p21286665_121020_Linux-x86-64.zip -d p21286665_121020_Linux-x86-...