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

learn more… | top users | synonyms

0
votes
1answer
7 views

mod_sed - apache+sed - problems with backslash

I have just started using sed and are having a problem when using sed from Apache mod_seq. The task is to change a web service post to a file upload post. 1) Test with file from command prompt ...
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 ...
0
votes
1answer
3k views

Sed error “sed: -e expression #1, char [#]: extra characters after command”

sed '/\r$/ {N s/\n//}' sed: -e expression #1, char 10: extra characters after command I want to understand what is wrong with my command line. When I can do the some of following in a script ...
-1
votes
2answers
2k views

Why escaped single quote doesn't work in grep?

I am trying to match a string: * * * * * /usr/local/bin/growlnotify -t 'helloTitle' -m 'helloMessage' -n 'myApp' -sw with: crontab -l | grep '^[^#].*/usr/local/bin/growlnotify.*\-n \'myApp\'.*$' ...
0
votes
1answer
54 views

Tmux status sed output different from cli

I've been looking at this for a while now, but I cannot find a reason. When I run the following in a cli, it works as expected: $ uptime | sed "s/.*average: \(.*\), \(.*\), \(.*\)$/\1 \2 \3/g" 0.65 ...
1
vote
1answer
129 views

Delete newlines using Stream editor (sed)

I need to write a sed script that places the actual text of the subtitles in a srt file on a single line. If this text originally was split over multiple lines, the line break and possible ...
0
votes
3answers
7k views

How to use sed to replace a pattern at the end of each line in a file with fixed text?

I want to compare two files of around 40 MB of comma separated values with lines like this: hstar,default,"T9883Z ",0d59,c801,7332,5,20120914,4.343618767 For the two files, the last entry which ...
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
8 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
35 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 ...
2
votes
2answers
543 views

bypass character limit in Sed and the replacement / character?

I'm Using windows Xp. I want to replace a word of length 200,000 characters and CMD has problems (the input line is too long). With Linux, does the terminal have same length problems? If I replace ...
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 ...
2
votes
1answer
7k views

sed to remove all whitespace from a line

I want to use sed to remove all space characters from a text file. At present I am using this command: sed 's/ //' test.txt > test2.txt This works in the sense that it removes the first space ...
2
votes
3answers
5k views

delete only first hit /match with sed

$ echo -e "AsometAhingA\nsomethingA\nASomethiAng" AsometAhingA somethingA ASomethiAng $ echo -e "AsometAhingA\nsomethingA\nASomethiAng" | sed "s/A//" sometAhingA something SomethiAng $ I know that ...
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 ...
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" ...
0
votes
1answer
47 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
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
3answers
2k views

Using sed to replace text from a list of files from find

Given the following find command: find . | xargs grep 'userTools' -sl How can I use sed on the results of that command? output: ./file1.ext ./file2.ext ./file3.ext
1
vote
2answers
53 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
1answer
110 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 ...
8
votes
8answers
8k views

List only the device names of all available network interfaces

I want to get a list of all available Network-Device Names on my Linux server. I figured that netstat -a would do the job, however netstat produces quite much output: eth0 Link encap:Ethernet ...
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; ...
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
63 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
37 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
1answer
445 views

Perform a math operation on all numbers in a file

I have a list of pixel values in a file, and need each to be half its current value. The pattern for the value is always 123px where 123 varies drastically. How can I half each pixel value? I'm ...
5
votes
3answers
1k views

Am I using sed properly to perform this conditional replace? Is there a better way?

I have a space-delimited file that's about 3200 lines long. Each line contains 7+ fields. What I would like to do is edit the file with sed so that every line containing a certain variable in field 5 ...
2
votes
2answers
285 views

sed in bash not working

I am trying to use the stream editor sed in bash to replace a string in a file to a new string that I entered, I have this thus far: echo "name to change" read updatenaamold echo "enter new name:" ...
2
votes
1answer
1k views

how to remove html comment tags using sed?

I want to remove comment tags in an html file. <!--- <script save and execute me> --> must become: <script save and execute me> I tried sed -i s_^<!-- \(.*\) -->$_\1_ ...
2
votes
2answers
198 views

Replaces images\(.*)“ with images/\1” in all files?

I've got a bunch of html files, and all the img tags have the slashes the wrong way! Here's an example (except it's one line in the code, split here for ease of viewing) <a ...
1
vote
1answer
305 views

Batch search and replace file path

So I've got lots of m3u playlists created on my Windows machine inside a folder with file paths to tracks as: D:\path-of-mp3 So first I want to replace all the \ with / and then D: with ...
1
vote
2answers
232 views

replace all names with an alternative using Stream editor (Sed)

I got this question on a task. Nothing works.. Can someone help me? Write a sed script that replace all names with an alternative, search for every words that: Start with a capital, Longer than ...
1
vote
4answers
2k views

using sed to replace two patterns within a larger pattern

Using sed how could I replace two patterns within a larger pattern on a single line? Given a single line of text I want to find a pattern (Let's call this the outer pattern) and then within that ...
0
votes
1answer
28 views

Replace '-' char using sed

I have a text file, quite similar to this one: JACK BLACK 123456 -1245368 - BRIDGET RED 1245 548425 + JOHNNY HOMUSS 55482 -4325 - I wanted to use a sed command ...
0
votes
3answers
95 views

How do I exclude match and change only specific character with sed

I am trying to use sed to replace '0' with the word 'correct' (I am using echo $? to validate my script and I want to replace the output of echo). The problem is that I have more text in the output ...
0
votes
0answers
14 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
146 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
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" ...
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: ...