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

learn more… | top users | synonyms

1
vote
2answers
42 views

sed + remove char after specific word

I want to delete the last "." only if "." exist after "usa" word my sed command only removed the last "." , but what need to add to the sed syntax (a rule) in order to remove the "." only after ...
1
vote
1answer
41 views

why this simple sed script didn't work “nginx -V 2>&1 | sed -r 's/--/\\n/g'”

the output of "nginx -V" is a mess. nginx version: nginx/1.9.3 (Ubuntu) built with OpenSSL 1.0.2d 9 Jul 2015 TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fPIE ...
0
votes
2answers
43 views

Shell output from one command as input to other

I am trying to automate Forever JS to keep my dev server running and for that I need to check and stop the forever process to start another one. By running sudo forever list I get the following ...
2
votes
2answers
61 views

Print lines of a file between two matching patterns [duplicate]

How can I print all the lines between two lines starting with one pattern for the first line and ending with another pattern for the last line? Update I guess it was a mistake to mention that this ...
0
votes
1answer
69 views

parse HTML in Bash (when grep just isn't enough)

This is driving me insane, as I'm sure there must be some program doing the job but I just can't find it. To be noted, I'd be on ARM/Raspberry so unfortunately Xidel is not an option here, unless ...
3
votes
2answers
77 views

Find each line matching a pattern but print only the line above it

I need to find a string and need to print the line above it. case1: The same line won't have the more than one matching pattern ie) consider a file containing $cat > para returns between the ...
4
votes
3answers
373 views

How to replace a multi line code with sed?

I have a large file which has special characters in it. There is a multi line code there, that I want to replace with sed. This: text = "\ ------ ...
-3
votes
4answers
50 views

How to print only the ticket numbers?

Following is the content of the file and i need to print only the ticket numbers which are enclosed in "[]". Curious to know if this can be done using both sed and grep commands. ...
-2
votes
1answer
18 views

Remove some elements of a string and replace with others

How can I convert this : RS.PK.03.01.4200.03.014.01 to man03140101? What needs to be done? Text before 5th "." has to be removed : RS.PK.03.01.4200. The remaining text should be converted ...
-1
votes
3answers
32 views

How to delete the first few lines of data and a specific matching numeric number until the very end of data

51 0 0 5 0 0.0 0.0 0 1 2 3 4 5 6 7 8 1, 2 0.998 0.567 3, 2 Rs12345 0.7 0.2 3, 2 Rs31256 0.56 0.311 3, 2 Rs25691 0 0 012.1313010310 0.1213212 0.2121331321 0.0121654564 0.254564564 ...
1
vote
1answer
27 views

Busybox ASH inside initrd has a problem when piping tee to sed

I'm trying to log the early boot output from the init script. This is what is working: mkdir -p /run/log && \ mkdir -p /tmp && \ mkfifo /tmp/stage-1-init.log.fifo1 && \ mkfifo ...
3
votes
1answer
46 views

Replacing a & in XML correctly?

I want to replace a '&' with &amp; Except the following occurance of XML special characters. " &quot; ' &apos; < &lt; > &gt; & &amp; I tried the ...
-2
votes
1answer
63 views

How to find the word before a match

I have the following log file. I need to know if there are any fault / suspect condition using a shell script. I need to find fault and check the previous word, if it is greater than 0 then there is ...
3
votes
2answers
224 views

sed capture groups not working

I have a string of the format [0-9]+\.[0-9]+\.[0-9]. I need to extract the first, second, and third numbers separately. As I understand it, capture groups should be capable of this. I should be able ...
-1
votes
1answer
37 views

Extract value from XML

I have this XML: <results><testsuites><testcase name="XXXX (XXXXX)" time="20.3817"><result>success</result></testcase><total_time value="20.3830" ...
0
votes
1answer
24 views

Using sed command change a string on a certain line with a certain string

Basically what I need help with is, I need to use sed to change a string in a file only on the 4th line if it contains a string called "test" So basically What I got right now is: sed '/test/ ...
0
votes
1answer
33 views

sed: -e expression #1, char 44: unterminated 's' command [closed]

I am aware that this type of question has been asked by many people. However, I am a beginner in Linux so I hope you can please help me this line of code: sed -i ...
-1
votes
2answers
50 views

What does sed 's/5//g' mean in this command line?

Here is output of df -h. [root@ip-10-0-7-225 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 8.0G 1.5G 6.6G 18% / devtmpfs 478M 0 478M 0% /dev tmpfs ...
1
vote
1answer
27 views

insert string for missing value

I've run into some problems with editing a text file I've received due to some missing values in a specific column for some rows. For example, here is what the file looks like (mostly): ID10 dad ...
1
vote
2answers
23 views

Strip certain objects out of a flat file database

I have a flat file database and I need to strip certain objects from it. There are numerous blocks in the file but I am interested in 2 objects in the OBJECT NickCore block. Example below: OBJECT ...
1
vote
1answer
31 views

How do I get an acceptable last modified timestamp for my Jekyll site using a shell script?

I would like to be able to provide last modified timestamps to my Jekyll posts and pages using a shell script. The problem is that I do not know how to automatically generate an acceptable timestamp. ...
1
vote
2answers
45 views

Change a string with sed

After using a filter to get a list of process like the next one: FOO_AAAAA_00001 FOO_BBBBB_00001 FOO_ABABAB_0000 FOO_ABCCDAA_00 FOO_12345678_0 FOO_JJJ_00001 FOO_VLLLL_00001 FOO_KKAKAA_00001 The ...
0
votes
1answer
42 views

How do I remove a line if it begins with a . or a > using sed?

For the life of me I can't get this to work properly (forgive me if this is a trivial question). I have a text file that have lines that begin with either a period, ".", or a right arrow, ">". I need ...
3
votes
2answers
54 views

How can I do a binary search of a text file for a specific character string?

I have a text file that contains a large number of records, each on a single line. Some of the records have special characters that have been corrupted, and I'm attempting to find those by looking for ...
1
vote
3answers
103 views

sed to remove all after a string?

I'm trying to use sed to remove the rest of a line after: HTTP1.1" 200 I can't figure out how to get sed to understand I want that whole thing as a string to match, including the double quote and ...
1
vote
1answer
31 views

Escape >');} < / in sed

In 30 files in 30 directories, I want to find: script>');} < /script> and replace it with: script>');} < /script--> What special characters do I need to escape in the find ...
0
votes
1answer
55 views

replace long text string (script with MANY special characters). sed, awk, grep

My site was hacked / infected. I replaced the url of the malicious link, but other elements in the malicious script are still making my site get blocked. Without inserting a hundred or so "escapes", ...
0
votes
2answers
31 views

sed + add comment to IP - only if IP is matched exactly

my target is to add "#" to the IP's with sed, But Only if IP is matched exactly!!! for example: sed 's/72.16.90.12/#72.16.90.12/g' /etc/hosts more /etc/hosts 72.16.90.121 host1 ...
1
vote
1answer
36 views

sed + update 4 different IP's in hosts file in one sed command

how to run the follwoing sed command in one command line? sed -i s'/12.1.0.11/#12.1.0.11/g' /etc/hosts sed -i s'/12.1.0.12/#12.1.0.12/g' /etc/hosts sed -i s'/12.1.0.21/#12.1.0.21/g' /etc/hosts ...
0
votes
1answer
56 views

Sed command for performance improvement or tr command for the same

I have a command to replace the non printable characters and single quotes from a file but its taking more time to execute as I am replacing these characters for multiple files and the files size is ...
0
votes
1answer
30 views

Remove file name when recursively counting number of occurrences of a pattern

When I run my grep command: grep -rc 'PATTERN' . it prints out the number of lines that the pattern occurs, but it looks like this: ./hotel_232424.dat:234 and so on... How would I remove the ...
1
vote
2answers
68 views

How to replace multiple blank lines with a specific non-blank line?

The sample input is 1 2 3 4 5 6 7 8 9 The expected output is 1 2 3 --- 4 5 --- 6 7 8 --- 9
0
votes
1answer
29 views

Delete Non numeric row from a csv

I have used sed to allow only numeric and csv format ,I have used sed '/[^0-9, -, .]/d' as regex. It has still "_","1-0","1-1" character as o/p which worries me. sed 's/'"$(printf '\015')"'//g' ...
0
votes
3answers
38 views

List out the original IP Address of the host

I have following content in the file. I would like to print the IP address which is Under Name. Server: 17.128.100.12 Address: 17.128.100.12#53 Name: Testserver1 Address: 17.146.118.156 ...
0
votes
1answer
22 views

How do I use sed to change },{“Foo” to }\n{“Foo”?

I have a 55MB JSON file with a huge number of objects that are separated by },{. I would like to have one object per line and get rid of the comma. For one thing, I'd like to be able to look at the ...
0
votes
1answer
46 views

Multiple sed commands in a file

I want to save a .txt file to 2 separate .txt files using command placed in a .txt file. I can use sed -e '1,20 w file1' -e '21,$ w file2' input.txt But how would I plac e this command in a file ...
3
votes
1answer
88 views

Print some lines before and after pattern match excluding lines matching another patterns

I use awk on Solaris to print 5 lines before and after a pattern match. Currently, the following one-liner does the job: /usr/xpg4/bin/awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print ...
3
votes
1answer
36 views

grep output of cdrecord

I would like to parse the output of cdrecord/wodim using grep. cdrecord -v outputs lines like Track 01: 49 of 75 MB written (fifo 100%) [buf 100%] 10.2x. The problem is that cdrecord uses ...
0
votes
2answers
49 views

Collecting network information

I need to collect information about the network usage of each process. Nethogs presents the data I need in real time, I am trying to save the output to a file in order parse it and plot the data. ...
0
votes
4answers
47 views

Print only unique lines from file not the duplicates

I have a sorted words list, line by line file like so: apple apple grapes lime orange orange pear pear peach strawberry strawberry I only want to print out unique lines and drop duplicates: grapes ...
1
vote
1answer
54 views

How to remove date format

I have the following content in the file. I would like to remove dates and the underlines from the file using sed. let me know if this would be possible to do with grep either. Can someone assist on ...
-4
votes
2answers
41 views

Convert all text in a file to uppercase using sed and interested to use range operator [duplicate]

I am trying to : Convert all text in a file to uppercase using sed and interested to use range operator. can some one please help me here. content of Sample.text: unix is great os. unix is ...
0
votes
2answers
30 views

Joining certain lines of text together before modifying them

I have a cricket commentary like - 0.3 Richardson to RG Sharma, 2 runs, gentle, non-swinging length ball on off, Rohit seeks to pick it up. Hit high on the bat and spooned over the returning Mitch ...
0
votes
1answer
35 views

delete line that contains a case insensitive match

I have a file that contains information as so: 20 BaDDOg 31 baddog 42 badCAT 43 goodDoG 44 GOODcAT and I want to delete all lines that contain the word dog. This is my desired ...
1
vote
2answers
73 views

Save file after using sed command

I am using following command to replace yyyymmdd to YYYYMMDDHH24MISS in my file: sed -e 's/\('yyyymmdd'\)/\('YYYYMMDDHH24MISS'\)/g' filename After I run the command in PuTTY, it displays the file ...
1
vote
1answer
41 views

Linux + capture only the IP's from mount command

please advise how I can to print only the list of the IP's ( in the end of the lines ) , from mount output mount netapp64:/lunggg/OracleTeam/OracleCDs on /oracds type nfs ...
1
vote
2answers
120 views

sed insert character at specific positions

I have hundreds of *.txt files which have a common format. I can insert a comma at a specific position in one file, how can I generalize the below code to apply this operation at several places for ...
1
vote
5answers
527 views

Grep value from json file

my json file looks something like this [{"product":"Apple","id":"2134"},{"product":"Mango","id":"4567"}] I want to grep/sed/awk 'id' for given 'product'. Output: Enter product : Apple Your ...
2
votes
1answer
25 views

grep awk or sed a CSV Row containing a certain part of a web address

I am trying to clean up a Squid log file and I want to delete rows with a website containing "/0/" in the 11th column. An example: Row1: column1, column2, column3...column10, ...
0
votes
1answer
68 views

Split string into array and print each element on a new line with commandline

I'm having a String which is seperated by commas like a,b,c,d,e,f that I want to split into an array with the comma as seperator. Then I want to print each element on a new line. The problem I'm ...