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

learn more… | top users | synonyms

2
votes
6answers
176 views

Bash - Split the previous commands parameters

How would one parse the previous command in bash? Example: root$ ssh foo@1.2.3.4 root$ echo !$ &>/tmp/foo.txt root$ cat /tmp/foo.txt foo@1.2.3.4 Goal: Send just the ipaddress 1.2.3.4 to ...
1
vote
3answers
171 views

Cat 2 files and avoid duplication of lines

I have the file1 with the following content {"name":"clio5", "value":"13"} {"name":"citroen_c4", "value":"23"} {"name":"citroen_c3", "value":"12"} {"name":"golf4", "value":"16"} {"name":"golf3", ...
1
vote
3answers
143 views

grep for strings that were found in a previous statement

I'm trying to find out if an address definition is used inside of fortigate configuration file. I extracted the section out of the configuration file, that contains the addresses. In that section the ...
0
votes
7answers
1k views

Unix sed command to find multiple string patterns

Scenario here is I need to replace "$$file_name=" value.. I have some 150 file names in a file as mentioned below.. Eg: $$file_name=abc.bbb.ccc to_be ---> $$file_name=abc.bbb.cccV1 AS_IS : ...
2
votes
2answers
2k views

How can I filter those “Permission denied” from find output? [duplicate]

I started using sed recently. One handy way I use it is to ignore unimportant lines of a log file: tail -f example.com-access.log | sed '/127.0.0.1/d;/ELB-/d;/408 0 "-" "-"/d;' But when I try to ...
4
votes
3answers
236 views

Check for, and add, missing timestamps to individual lines in a file

I have a file in the following format: ABCD 01206001022T01YA022T01YA022T07SO 09:20:38 ABCD 01206001022ACION 09:24:40 ABCD 04006001021S01UK 09:24:42 ABCD 7878696621321312 23213213213213 ABCD ...
2
votes
6answers
4k views

Repeat each line multiple times

Would like to have each line in a file repeated a fixed number of times. e.g. have each line repeated four times: a b c becomes: a a a a b b b b c c c c I've done some searching, and there are ...
1
vote
5answers
491 views

delete lines in a csv file older than 7 days

I have a csv that I need to remove all lines that are older than 7 days. This is the format of the csv Person ID VIP CS SS LT FTLT PS Modified Datestamp T001028 1 1 1 0 0 0 ...
10
votes
8answers
2k views

How to remove multiple newlines at EOF?

I have files that end in one or more newlines and should end in only one newline. How can I do that with Bash/Unix/GNU tools? Example bad file: 1\n \n 2\n \n \n 3\n \n \n \n Example corrected ...
0
votes
2answers
485 views

sed - replace complex lines in a file using variables

How do I replace a complex line in a file using sed? For example I want replace a udev rule in /etc/udev/rules.d/70-persistent-net.rules. This doesn't work: OLD_RULE='SUBSYSTEM=="net", ...
1
vote
1answer
2k views

Deleting commented lines in a text file using sed

I am a sed novice. I would like to use sed to delete commented lines in a text file. In my series of text files, commented lines begin with either the # symbol or the @ symbol (i.e., they are ...
-1
votes
3answers
172 views

Removing second colon

Trying to create a simple script that lists mass mailing by the queue number that appears in /var/log/maillog. I'm starting off with this: [root@ditirdlns01 ~]# lsMails(){ grep -i ...
4
votes
7answers
696 views

Need some sed magic: Moving marked lines to the beginning of a file

I find myself in dire need of some sed magic (I really need to sit myself down and learn this). I have a file with lots of lines. After reviewing it, I've marked some lines by adding a star (*) to ...
1
vote
2answers
3k views

How to use sed with round brackets?

I have a bunch of .php files that I wanted to replace all occurrences of a string. find: jQuery(function replace: head.ready(function I thought I was doing it right by using: find . -name '*.php' ...
4
votes
3answers
8k views

extract part of string using sed

ls lib/oracle-11.2.0.3.0.txt | sed 's/lib.\([oracle.*]\)\.txt/\1/' It is giving the whole string instead of just oracle part until .txt What am I doing wrong? I can do it using awk as follows, but, ...
2
votes
2answers
530 views

Add a suffix string to end of each line? [duplicate]

I have two files: file01: line1 line2 line3 file02: A B C And I want to get line1 A line2 B line3 C I could possibly write a Perl script but it is better if I don't need to. I have tried ...
0
votes
4answers
5k views

Extract substring using regular expression on a Unix file

I have file with below contents . /ABC/RTE/AD_900_VOP_123/OPP /ABC/RTE/TRE/AD_900_VOP_145/BBB /ABC/RTE/AN_900_VFP_124/FBF /ABC/RTE/HD_900_FOP_153/WEW /ABD/RDV/AD_900_VOP_123/OPP ...
4
votes
1answer
150 views

How to follow and seek in a file being piped through a filter, in less

I basically wish to seek, search and follow a growing log file after passing it through a sed filter. I figured I need to follow a file with tail -f pipe it to sed and then pipe that to less. For ...
4
votes
4answers
717 views

What does <<< mean? [duplicate]

What does <<< mean? Here is an example: $ sed 's/a/b/g' <<< "aaa" bbb Is it something general that works with more Linux commands? It looks like it's feeding the sed program with ...
2
votes
2answers
166 views

linux & solaris - separate netmask IP's from ordinary IP's

I have file with IP address and netmask IP's my target is to cut the netmask IP's from the file_with_IPs.txt and paste them to another file as file_with_only_netmask_ips.txt remark - netmask IP can ...
-3
votes
4answers
780 views

perl one liner + how to replace any last IP address octets

How to replace any last IP address octets (four octet ) to 0 remark: Implementation should be by Perl one linear on linux machines for example 192.9.200.124 will replaced to 192.9.200.0 ...
-1
votes
1answer
250 views

SED command and filenames with space

I was hacked, for my php files was infected. Example: http://www.nwww.ma.mk/oscommerce/configweb/apexfash-wp-blog.txt Bad Code: <?php ...
2
votes
4answers
3k views

Using sed, how to format one word per line, removing white space

I'm trying to replaces patterns and cleanup a file containing multiple words to get one word per line. The result is achieved using this command line: sed -e '/^[[:space:]]*$/ d' \ # ...
6
votes
1answer
2k views

Removing leading zeros from DATE

I made an alias of the date command to display date in the following format: 2013.06.14.12.10.02 using this command: alias date = date +"%Y.%m.%d.%H.%M.%S" Everything works great, except I ...
4
votes
2answers
506 views

Use sed or awk to join lines in a certain pattern?

Not sure on how to turn this input: A B C apartner bpartner cpartner into this output: A apartner B bpartner c cpartner I have this pattern in a 80 line file that needs to be 40 line. Also, how ...
-1
votes
3answers
764 views

run file from different directory [closed]

I have a directory mainfolder with a subdirectory execution which contains a configure script. I can switch to the execution directory and run ./configure and it works fine. Now I'm trying to figure ...
4
votes
6answers
13k views

Using sed to find and replace complex string (preferrably with regex)

I have a file with the following contents: <username><![CDATA[name]]></username> <password><![CDATA[password]]></password> ...
5
votes
3answers
2k views

print lines between start and end using sed

I need to print the lines between two delimiters. For example, given the input fluff1 fluff2 BEGIN good3 good4 END fluff5 fluff6 BEGIN good7 good8 END more fluff I want the output to be good3 ...
2
votes
3answers
142 views

Delete lines containing repeated text

I have a file containing two paths on each line. I want to remove the lines containing the same path twice. I work on Linux and Solaris. I would like a one-liner in sed or awk or perl. Example input ...
0
votes
4answers
68 views

How to make 1:52 to 01:52 with eg.: sed?

INPUT: a|2013.06.13. 13:22|xx b|2013.06.13. 1:52 |xx c|2013.06.13. 2:26 |xx OUTPUT: a|2013.06.13. 13:22|xx b|2013.06.13. 01:52 |xx c|2013.06.13. 02:26 |xx How can I make the 1:52 to 01:52 in ...
2
votes
3answers
1k views

I want to find duplicates in a file and add a character to the end of the line on the 1st match

I am trying to find duplicates in a file and once a match is found mark the 1st match with a character or word on the end of the line. eg my file (test.html) contains the following entries host= ...
2
votes
1answer
158 views

Replace every odd or even occurance of a pattern in a file

I want to replace either every odd or even occurrence of a pattern. Look at the following example: $ echo aaaaa | sed -e 's/a/b/' -e 's/a/c/' -e 's/a/b/' -e 's/a/c/' -e 's/a/b/' bcbcb Is there some ...
2
votes
2answers
2k views

Replacing text between two HTML Comments

I am new to the world of sed/awk and regex in general and have been studying their usage, but have been floundering trying to meet my need: I have an htm page that has a single line notice that needs ...
0
votes
3answers
237 views

Inserting the results of a for loop into an html file - BASH

I have a script that takes the results of a command and puts them into a html code. Here's what I have so far... #!/bin/bash list_dir=`ls -t downloads/` for i in $list_dir do #---- # echo ...
2
votes
2answers
504 views

sed command to leave two decimals and remove the rest after comma

I have a numeric value, for example 19.3478 or 22.456 or 10. I would like to remove extra decimals if there are more than two decimals, so that there is never more than two decimals after the comma. ...
2
votes
3answers
2k views

Easy way to parse syslog date format

I'd like to write a script that analyses the last week's syslog. But my syslog logs in a stupid date format, e.g. "May 22". If it logged as 2013-05-22, this task would be trivial. Is there a way ...
2
votes
1answer
128 views

SED Showing CRLF While Vim Not Showing

Why sed l\;q shows a CRLF while opening the file in Vim with :set list doesn't show any CRLF
4
votes
3answers
3k views

How to sed a range of lines?

I have this: sed -i '/^$/d' temp_spec.rb which is stripping blank lines and works well. How can I make it only do this for lines 5-999 (or ideally 5 to end-of-file). I tried: sed -n5,999 -i ...
3
votes
3answers
99 views

How to select 30 files and do a bunch of sed commands on them

I want new copies of the files, so I want to do something like: dir *.rb foreach file make a copy of the file, e.g. 'blob.rb' to 'blob_processed.rb' do the 50 sed commands to process the ...
4
votes
7answers
5k views

Can sed remove 'double' newline characters?

I have a document with a lot of empty lines. How can I remove them when there are 2 or more together. I tried sed "s/\n\n//" file but it didn't work. No error.
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 ...
5
votes
4answers
533 views

sed how to substitute when string has “http://” in it?

I have a file xx that has the following contents: @base_url = "http://dmstaffing-stage.herokuapp.com/" I want to use sed to eliminate this line (replace with nothing). I have used this sed ...
4
votes
2answers
1k views

How to only substitute lines that match several patterns in sed?

$ echo -e 'CH12\nCH23au' | sed '/^CH/s=^=<b>=' <b>CH12 <b>CH23au I know I can match lines starting with CH by ^CH but how can I match multiple patterns? Example: Input: CH12 ...
2
votes
0answers
1k views

sed couldn't flush stdout no space left on device?

What could be the reason for this error : sed couldn't flush stdout no space left on device This is come of the stuff that i am doing at last in my code sed -n '/.*needs to be executed ...
4
votes
3answers
1k views

How to share a GNU sed script between Linux and Mac OS X

I have a GNU sed script I use on Linux; it is installed at /bin/sed and it seems it contains GNUisms. I have collaborators using Mac OS X. They have installed (non-GNU) sed, located at /usr/bin/sed, ...
3
votes
3answers
179 views

sed + how to remove character/s that start or ended on each number

How do I remove the . character(s) that start in the beginning of each number or end on each number? Remark – perl one liner also good alternative for sed. Example input: .23.12.44.5. .233.3.3.3 ...
3
votes
3answers
193 views

checking data in columns when a data or some may be missing or present?

I am not sure if this possible. say i have columns like : Team Colour Game Rainfall PlayerName XYZ Blue Cricket Yes Kapil suppose i need to search ...
2
votes
2answers
347 views

remove only the first blank line sed

there are similar questions here but none matches my problem exactly. How do I remove only the first blank line from a file using sed? Let's say I have a b c And I want a b c As output.
6
votes
4answers
4k views

Why is sed giving me an error about an unterminated `s'?

I have a set of sed replacements in a bash script and am getting an error about an unterminated `s' command. Here's what the sed line looks like: sed -n -e "s/TMPFOO1/$FOO1/" -e "s/TMPFOO2/$FOO2/" ...
3
votes
3answers
96 views

how to form a sed expression containing escaped characters

Given a sed expression (and GNU sed 4.2.2 on ArchLinux) /match/i\tline1\n\tline2 which should insert two tab-indented lines above the match, I find that the escaping of the first character (in the ...