"sed" ("stream editor") is a Unix utility that parses and transforms text files.

learn more… | top users | synonyms

1
vote
1answer
24 views

How to Extract Multiple substrings from Log FIle

I am trying to extract the timestamp and the number string in the URL called in an apache logfile that looks like this: 123.456.78.90 - - [16/Dec/2014:06:27:30 +0100] "GET ...
0
votes
1answer
27 views

What does `-n` option in sed do?

This is the man page entry for -n: -n suppress automatic printing of pattern space I notice that when not using -n for certain operations, each line is printed to stdout (and the requested ...
3
votes
0answers
39 views

Can I create a “file” that, when opened, actually gives the output of a command?

I've found myself in a couple of situations now where I'd like to have such a "file" that essentially runs a script whenever it's "opened", allowing me to "read" it's output. For example, I might ...
1
vote
1answer
34 views

How to delete the 3rd occurrence of a pattern in a file, and beyond

How can I find the third occurrence of a pattern in a file (Note: not in a line) and delete the line containing the pattern and n lines below that (say, 5 lines below). e.g., COVER fafjasfj isfapifj ...
2
votes
2answers
25 views

Sed replace between 2 strings with special character

I have an XML file containing a code and to use it with xmllink I need to remove a link. XML file containing: <xml version="1.0" encoding="UTF-8" standalone="yes"?> <PackingList xmlns="Link ...
0
votes
2answers
22 views

Replace random string using sed

How do I replace random strings using sed. For example if I have a text file like this: EF125353.1 to be replaced 1 EF125353.1 to be replaced again 2 EF125353.1 to be replaced etc etc 3 ...
1
vote
2answers
41 views

use sed to replace a specific string with slashes

I have a big text file -a windows registry file- about 5.5MB and I have to remove a string "serv\b\Param\". Opening with gedit or nano doesn't work. It will either consume 100% cpu time for some ...
0
votes
0answers
7 views

Why does sed accept \s (only when not in a character group)?

Okay, so I have always used \s to match whitespace but now I have been having a bit of difficulty as with sed, while trying to do a negated character group match [^\s] I found this does not work. ...
1
vote
1answer
34 views

Using grep, sed or awk to find words in between? I want to be able to extract the package name until .el7

I am writing a script (bash/command-line) and I want to be able to extract the package name until .el7 x=dbus-sharp (an example package name - which changes) example text file: Building ...
0
votes
0answers
41 views

GnuWin32 / sed unexpected behavior in Powershell

I am using GnuWin32 tools on Windows Command Line/Powershell. What is see: 11:15 enlil D:\Users\x> Get-ChildItem .gitconfig | sed "s/ */ /g" D i r e c t o r y : D : \ U s e r s \ x M o d ...
0
votes
2answers
19 views

how to retrive value between double quotes with multiple double quotes in line using sed

I am trying to use sed to retrieve value of 'identifier' from below line which is string 'TestStudioJobResponseMessages' in below example, also I don't want to use string uuid in my sed expression as ...
0
votes
1answer
45 views

Awk script to run a command based on condition using 'if'

I have a piece of code here that basically takes a file called 'srcip' (which is just a list of IP addresses) and compares it to my '~/db' file which is just a tab delimited IP HOSTNAME database of ...
0
votes
1answer
38 views

is there a way i can either insert a character into a line or substitute and arbitrary character with itself plus some other carachter(s) in sed?

like say i have a string of numbers that constitute a phone number and are like so ########## and i want to format them like : ###-###-#### insert only puts in new lines, and i dont know how to ...
0
votes
1answer
23 views

How do I search for and delete just the endings of list of directories using 'sed' command?

How do I use sed to delete just the '-bak' portion of the following list of directory names: accesscode-bak adminconsole-bak adoptimizer-bak ads-bak ahcms2-bak alerts-bak alfresco-bak
1
vote
2answers
52 views

Grep output from multiple lines in a limited shell environment

I have been scouring the web for ways to search across multiple lines of output and then print the lines which contain the strings I care about. I am actually running this on a checkpoint firewall, ...
-3
votes
2answers
42 views

How can I use a “<” character in sed?

I am trying to replace this line with a <?php tag with sed using the command: find . -name "*.php" -type f -exec sed -i '/if(!isset($GLOBALS/<?php/d' {} \; When I run the script, it generates ...
1
vote
2answers
37 views

how to see contents of a file (cat file) but eliminate a certain string in many lines

I have a file like this: ins.pro.server.pro.net ins.pro-server2.pro.net ins.pro-server3.pro.net ins.pro-server4.pro.net I would like to cat this file but eliminating the specific string ".pro.net" ...
1
vote
1answer
108 views

Bash/Sed how to insert a string with special characters into a file

I have a script that I'm currently working on. And I've run into an issue where I need to prompt a user to enter a string, then encrypt that with sha-512, and then insert it into a specific file So ...
2
votes
2answers
41 views

Replace Line Breaks on matching lines, using AWK

I have the following data What i'd like to do is for every line, where there is no ,"555" at the end, I want to remove the the line break, \n, and replace it with space. So, the 'matching line' ...
0
votes
0answers
61 views

how to show battery percentage on gnu screen hardstatus line

I currently have this as my hardstatus last line on gnu-screen the ~/.screenrc entry is as follows (just incase someone want something similar) hardstatus alwayslastline '%{= g}[ %{G}%H %{g}][%= ...
1
vote
1answer
26 views

Get a range of lines from a file and replace a line in that range using awk or sed or both

I would like to replace a line in a section of the smb.conf file using either awk or sed or both if need be. Here's the section in the file... [CMI] oplocks = no wide links = no writeable ...
0
votes
1answer
21 views

Why this sed is not working?

I want to massively change some css references in more than 200 html files. Most of the files are static HTML generated automatically. Now, I need to change the location of some css files. So, I ...
0
votes
1answer
36 views

Extract text between two slashes and add it at the end of the line after a tab character

I have a text file looking like this: data/CON/001/raw_series_ST_MC_REG_SM.nii data/PAT/001/raw_series_ST_MC_REG_SM.nii I would like to achieve something like this: ...
0
votes
0answers
13 views

Sed :cant read scripts/MIRRC.in: No such file or directory

I'm trying to install miriad and while entering sed -e "s,@MIRROT@,$MIR,"scripts/MIRRC.in &gt; MIRRC " I get the error below sed: Can't read scripts/MIRRC.in : No such file or directory I'm ...
0
votes
2answers
145 views

Bash script: Use variable in sed to delete all but the last “x” lines of a file

i'm using the following bash script to delete all but the last 'x' lines in a log file: #!/bin/bash # Script to write to the log file every minute and delete all but the last # set time in hours ...
0
votes
1answer
25 views

Return / transform then return pattern with nulls

I'm using grep/sed to parse a large binary file full of nulls for some specific data. This is in a windows environment using gnuwin32. Assuming I had some to return some data from a binary file that ...
0
votes
2answers
13 views

How To Search & Replace From a Word to another in The Same Line?

Like I said,, I want to search each line, from a word at the beginning of the line, To another word at the end ! For Example, let's say that I've a text file, that contains these lines :- 1.RA.xm: ...
0
votes
1answer
37 views

Remove beginnings of email addresses from text using grep or sed

I have a text file with lines like the following: John Stevenson Johnnyboy34 john.stevenson@company.com 0320423\n Mike Anderson AndersMike mike@mikeltd.foo 0234234 How do I remove the "text" ...
2
votes
2answers
43 views

How to find the common paths from a list of paths/files

Prelude: Given a sorted input of a list of paths/files, how to find their common paths? Translating into tech term, if feeding the sorted input from stdin, how to pick the shortest proper prefix ...
0
votes
1answer
31 views

Bootstrap pkgsrc on macosx (10.9) error

I am trying to bootstrap pkgsrc-2014Q2 on OS X 10.9. The script complains: cd /Users/tiramo/Downloads/pkgsrc-2014Q2/bootstrap/work/wrk/pkgtools/bootstrap-mk-files/work/bootstrap-mk-files-20140516; ...
0
votes
1answer
39 views

Is \d equal to [0-9] in sed?

7 00:00:30,008 --> 00:00:30,066 by line 8 00:00:31,038 --> 00:00:34,050 or later in the nineteen seventies it was usually a 9 00:00:34,005 --> 00:00:38,634^M video consul but the council was ...
0
votes
1answer
49 views

How to pass output of command to sed

My sed command in #Update key in config file. does not get the contents of the variable $GETKEY Someone help me? # Get key from output of the website. GETKEY=`wget https://www.badips.com/get/key ...
0
votes
0answers
28 views

binary substitution in (audio)streams with bbe or sed

I try to do some stream manipulation with webradio streams. Goal is to use a pattern in triggerfile to substitute some seconds of the instream to silence in the outstream I found bbe to possibly fit ...
0
votes
2answers
276 views

Increment version text stored in a bash script file

I have a bash file and I want to store a version text in it (preferably "echo version 1.0.1" so that it automatically prints out its own version when executed) I am trying to make a command group ...
0
votes
1answer
105 views

sed: What does exit code 2 mean?

Case I am trying to replace all occurrences of <value>*</value> into <value>file:\\</value> in a designated file test.txt. I work on Windows and use sed I have installed with ...
1
vote
1answer
55 views

Run sed as a one-off ssh command

I would like to substitute a string with another in a file on a server of mine. I've tried doing this: ssh $REMOTE_HOST sed 's|export ${KEY}=${VAL}|export ${KEY}=${NEW_VAL}|' "$ENV_FILE" And a ...
0
votes
1answer
54 views

Replace negative values in a file with zeros

I want to replace all negative values in a file with zeros. How can I do this in awk? I tried with gsub but gsub(-*, 0) doesn't work... Any ideas? My "code" is awk '{gsub($(!/-/),"0",$2); print $1 ...
3
votes
3answers
77 views

Sed replace only in even numbered lines of a file when replace commands are written in a file

I have all the replace commands in a file (say replace.sed) and i use it with -f flag of sed (sed -f replace.sed InputFile). But now i ran into a condition where i need to apply these replace rules ...
1
vote
1answer
58 views

Non case sensitive search case sensitive replace

How do I search/and replace like this using sed or another tool FOO => BAR Foo => Bar foo => bar That is: Look for foo regardless of case, and replace with the same case pattern. One ...
2
votes
1answer
389 views

sed, insert file before last line

The following inserting file method for sed used to be working, even before last line, but not any more. Is it a bug in the current sed? Demo of inserting file method with sed: mkdir /tmp/test ...
0
votes
0answers
19 views

How to colorize the output using sed - no GNU tools available

I'm using a short alias in my .profile file to colorize the output of the sdiff command, just to make it easier to spot differences. The alias is like this: alias color_diff="sed 's/[|< |> ...
0
votes
1answer
33 views

Escape brackets when using SED

I would like to replace the value varchar(36) with char(36) in a file by using sed. I am trying with sed -i ’s/varchar(36)/char(6)/g’ calls_contacts.sql But the command does not execute. What am I ...
1
vote
1answer
113 views

How to replace a line in an xml file with a set of lines stored in a variable or file using unix commands?

I have a xml file in which the line that needs to be searched is: SEARCH='<?xml version="1.0" encoding="UTF-8" standalone="no"?><SSC>' This searched value needs to be replaced with ...
2
votes
2answers
220 views

sed error when launching terminal on OS X

I get these error messages when launching bash or zsh in standard Terminal.app or iTerm2 sed: 1: "\#^system_type=# { s#^s ...": extra characters at the end of p command sed: 1: "\#^system_type=# { ...
1
vote
2answers
110 views

Adding text to the end of multiple files, minus one line( Adding return 0; at the end of each program in C)

I have a bunch of C programs from K&R and of course, no return statement. I was wondering if there was a way to cat to the end of each file (except one line before the end, so EOF - 1) the ...
0
votes
0answers
35 views

How to call “sed” on PDF files

I am able to find text on PDF files using pdfgrep. How can I sed them? I just want to change a pattern of text and I don't think I need a editor for that. Or do I? How can I achieve that?
0
votes
1answer
30 views

How to use sed to examine the line without specific content?

I made a toy file named toy, its content is like: aaa bbb My first idea is to use: sed -n '/[^a]/ p' toy bbb it prints out bbb, but when I added bb ab to the end of toy file. I found it lose ...
-1
votes
2answers
84 views

add line number after matched pattern in vim

I have raw sequences and I have to convert it to fasta format. so reads are like this: CTACGGTGTGCTCTTCCGATCTGACTATG AGTTGGTGTGCTCTCCCGATCTCGCTCCCTC GTGAGGTGTGCTCTTCCGATCTCCGGCAGTGTGCT and i want ...
4
votes
2answers
492 views

shell script to replace a keyword in a file with the contents of another file

I'm to create a .sh to replace a specific keyword in a file using the contents of an other file. template.html contains a unique string "PLACEHOLDER" it must be replaced with the contents of file ...
2
votes
4answers
103 views

Extract lines based on long list of line numbers

I have a long list of line numbers (35389208) that I do not want in my file. By line number I mean the line in my file (e.g. line 277). My list of line numbers I do not want looks like: 277 278 279 ...