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

learn more… | top users | synonyms

3
votes
3answers
302 views

Need to sed awk or grep output to extract strings

I have output which looks like this: "vancouver/news/vancouver-voices": { "status": 0, "time": 0, "timestamp": 1371298701 }, "vancouver/news/vancouvers-march-second-annual-success": { ...
1
vote
3answers
515 views

sed quotes and backslashes on cygwin

I am trying to extract a substring from a string with sed on cygwin. #!/bin/bash var1="foo\ bar" var2="baz" var3="$var1 $var2" # extract "foo\ bar" from "foo\ bar baz" var4=`echo $var3 | sed ...
1
vote
1answer
1k views

using sed/awk to parse XML tags

For the record, I've spent several days working on this with no luck. I'm working with XML files with data containing something like the following: <row id="67581917031" name="4022" ...
0
votes
3answers
4k views

remove text from file

I want to remove some text from file1.txt. I put the text in the file tmp and do: grep -f tmp file.txt But it gives me only the difference. The question is how to remove the difference from ...
1
vote
2answers
102 views

remove the zombie process from the output of ps

I m not looking to kill a zombie process. I m looking to avoid the display of zombie process in the ps command. Are there an option to add to ps command inorder to avoid displaying the zombie ...
2
votes
5answers
5k views

sed: extracting value of a key-value pair in a URL query string

I am trying to use sed to extract the value part of one of the many key-value pairs in a URL's query string This is what I am trying: echo 'http://www.youtube.com/watch?v=abc&g=xyz' | sed ...
0
votes
1answer
123 views

sed/awk: modify source file?

I'm trying to script some changes I need to make to a couple of config files. It's worth mentioning that I'm an expert with neither sed nor awk, though I'm far better with sed. Right now, I'm doing: ...
0
votes
0answers
53 views

How do I script a config file change

I'm trying to create a script to make the vi color change described here http://www.kavoir.com/2009/05/how-to-change-vim-syntax-highlighting-colors.html Trying to do it with sed but it's not working ...
3
votes
2answers
156 views

Prefix all lines with the first word in a file

I want to prefix all the lines of a file (except first line) using the first word in a file. Input: x.o: x.cpp /u/a.h /b.h \ /c.h \ output: x.o: x.cpp /u/a.h \ x.o: /b.h \ x.o: /c.h \ Can ...
0
votes
1answer
242 views

sed command working in command line but not in script [closed]

I have a script with the follow code: find . -name "*.html" -print0 | while IFS= read -r -d '' n; do sed -i -r 's/<font ...
1
vote
1answer
169 views

Generate CSV/TXT file from named zone file

I am in need of generating a csv/txt file from a zone file on a named DNS server. For examples I would like to generate a list of the hostname and IP from the zone file From this monkey A ...
-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\'.*$' ...
3
votes
3answers
1k views

Substituting a multi-line pattern in an HTML file

I have a series of HTML files that contain two lines like this: <body> <h1>Title</h1><p> <a href="url">Description</a><br> I want to replace this text with ...
0
votes
2answers
1k views

Replacing a dot with an underscore in a file using sed

I was trying to edit the output of a file using sed. The contents of file are cat /tmp/Group_RM t.p@k.p t.m@k.k I was trying to get the output as: cat /tmp/Group_RM t_p@k_p t_m@k_k I tried the ...
1
vote
2answers
342 views

netcat output into separate files using string delimiters

I want netcat to pipe the output of a tcp/ip connection to commands that examine the output and split it into distinct files separated by the strings "msg" and "/msg" from the output, something like ...
0
votes
1answer
126 views

Counting by number of occurrences in first column

I have an input file like this: ATTACK-RESPONSES id check returned root BACKDOOR ACKcmdC trojan scan BACKDOOR hack-a-tack attempt BACKDOOR WinCrash 1.0 Server Active ICMP Destination Unreachable ...
-1
votes
1answer
46 views

Inserting a string with sed

I need help to find and insert a string of characters using sed: Before: "AdminHostName" value="" After: "AdminHostName" value="my-text"
4
votes
1answer
4k views

Using grep to remove lines from a file which contain a string from another file

I have a file containing words (one per line) such as Dog Fish Cat Shoes I have a secondary file in CSV format such as 1,shoes,red 2,apple,black 3,fog,blue I would like to use grep with ...
0
votes
1answer
84 views

Perl or Sed to remove a web virus

I recently ran across a bit of code injected to all of the files on a web site and I need to use perl or sed to remove it across all the files. I am having trouble coming up with the exact pattern ...
8
votes
3answers
3k views

sed: how to replace line if found or append to end of file if not found?

With a single input file that only contains comments (starting with #) and VARIABLE=value lines, is it possible to replace a value for a single variable if found and, otherwise, append the pair to the ...
0
votes
1answer
366 views

Mass migration of EXIF GPS data (a.k.a. Escape from iPhoto)

I am trying to move my library of photos (over 12000) out of iPhoto for use in Adobe Lightroom and would like to include the GPS data I've added to the photos using iPhoto's in-app feature (This data ...
0
votes
2answers
346 views

Deleting line from file using SED in MultiUser Case

I have a scenario where multiple users are connected to a server using SSH. I have a file which is read and written by all the users. The file contains numbers like this - 14554 14887 23451 15135 ...
0
votes
3answers
659 views

Match and remove first and second pattern within xml tags

How can I match and remove first and second pattern within xml tags using sed or awk? Here is the example <data>A78-1-1134-HI-1</data> <data>T78-12-1346-AG-2</data> ...
2
votes
3answers
215 views

Using sed to change output format

How can I use sed to change the output format of a text file? My text file contains and diplays this when I call cat: 9/27/2002 9/28/2002 10/1/2002 10/2/2002 10/10/2002 10/11/2002 12/29/2002 ...
0
votes
1answer
217 views

Replace string with another string shell script

I have a file in the format: "data","data","data",data". Now if data has a " in it, then my parser cannot parse the file. So I want to use sed to replace " with """ but not where it sees "," as that ...
2
votes
1answer
164 views

What does `-e` option in sed do?

I am trying to understand a shell script that uses sed. I found that there were some places where sed was invoked with the -e option. I tried to see the man page and it just mentions, -e command ...
0
votes
2answers
91 views

Deleting all word occurences with sed preserving linefeed

I'm trying to delete a word's all occurences in a text file with sed. I have this file f1: alma a fa alatt nyari piros alma and I'd like to delete all occurences of "alma". I use the ...
-1
votes
2answers
141 views

Replace all numbers following a specific string with another number using sed or awk

I have tried several things but got no luck. I have an input file that has a lot of fields like this one weight=0.123456 mixed with other fields. I want to multiply all such weights by a factor, say ...
0
votes
3answers
701 views

Removing first line with pattern with _both_ awk and sed

Fairly easy. I'm looking for the simplest approaches in both sed and awk for removing the first line in a file that contains a specific string.
0
votes
1answer
264 views

Enable an epel repo via script?

I'm installing the Epel repo via a shell script, the repo comes by default disabled, I would like to enable it so the script can install further packages. The following install the Epel repo: yum ...
1
vote
1answer
252 views

error occur when i run awk command write in .sh file and run in cygwin terminal

i have cygwin terminal for run shell script(.sh ) file...it work good..but when i add awk command in shell script and then run Error occur /usr/bin/gawk.exe: error while loading shared libraries: ...
1
vote
2answers
427 views

Skype: Decode time stamps

I'm trying to extract the chat history between myself and my SO on Skype for OSX. I've managed to pull out the information and strip out the unnecessary XML formatting with the following command: ...
3
votes
5answers
2k views

Using sed to remove digits and white space from a string

I am trying to remove the first occurence of digit(s), the dot, the second occurence of digit(s) and the space before the word. I have come up with this regex: sed 's/^[0-9]\+.[0-9]\+\s//' input.txt ...
1
vote
1answer
96 views

Incorrect version of sed when compiling on OSX

I am trying to install crosstool-ng on OSX 10.6.8. At the configure stage, I run ./configure --prefix=/opt/cross, and I get the following output: ! ./configure --prefix=/opt/cross checking build ...
3
votes
2answers
2k views

SED: How can I print every line after first instance of string using Sed?

I have a file with a similar format... 16:28 asdfasdf 16:29 4398upte 16:30 34liuthr 16:31 34tertio How can I use SED to print out every line including and after the line with "16:30"? The result ...
1
vote
1answer
309 views

Subtract files from one another recursively between two similar directories

I'm trying to concoct a way to grab two (nearly identical) directories and show me the difference between all files in the two directories. Looking for two different things: 1- List all files ...
1
vote
1answer
2k views

How to use variables in sed on Windows?

I'm writing a batch script to automate build events on Windows, and as part of it I need to change some lines in a few files. So I'm going to use sed. But how do I use variables in sed inside a batch ...
0
votes
1answer
881 views

Grep issue (match two strings on same line)

Here I have some grep command which is not working correctly: cat file1.txt: apples Date: Sun, 24 Feb 2013 8:14:06 -0800 peaches melons cherry sky cloud green purple yellow cat file2.txt: apples ...
0
votes
3answers
225 views

Advanced sed command

I have a file (/usr/test.log) with a bunch of lines, of the form [enable/disable] [name] [stuff] For example: enable telnet max_pkt 0 max_payload 0 min_payload 1 disable_function 0 ...
1
vote
1answer
609 views

why is it true that three backslashes are needed on windows for sed replace

Refering to this question: Why is an extra \needed in cmd.exe to work with sed (MinGW msys-1.0) when \ is not a special character according to cmd /? (see last paragraph or here)? The following ...
0
votes
1answer
586 views

Multi-line find and replace across multiple files on linux

I have: Old Google analytics tracking code oldcode.txt New Google analytics tracking code newcode.txt 100+ html files *.html in one directory Is it possible to replace former with latter in all ...
2
votes
3answers
391 views

matching start of the line in cygwin regexp

I apply sed 's/^ bug*/__/' to ref bug bug ref and get ref __ __ ref The same is responded for perl, perl -ni -e 's/^ bug/__/; print'. Sample file can be downloaded ...
0
votes
1answer
722 views

Search & Replace Using Grep and Sed Command

I want to remove the weird / special characters from the bunch of text files. Here i used the following command to remove the weird characters but it gives me the error. Command : 1) grep -lri -e ...
2
votes
3answers
6k views

Bash: Find and replace text strings

I figured this would be easy, but I'm overlooking something simple: I have a text file called test. It contains, for example, the string Alfred Hitchcock. I want to replace this with Alfred\ ...
0
votes
1answer
306 views

Combining multiple data files with header while also adding a data column

I have multiple tab delimited data files that are separated by month in the format jan06.txt, feb06.txt, ..., dec07.txt. Within each file, it looks something like: Header1 Header2 Header3 ... Data1 ...
2
votes
3answers
839 views

How to replace one line for multiple lines in a file, programatically?

I have this config file I want to edit programatically. I always use sed to make small changes, but now I need to replace 1 line for multiple lines, something like this: some code # maintenance ...
8
votes
1answer
523 views

How to make sed omit not matching lines?

In the following example, sed matches lines starting with an a or a c and prints the first character of that line (a or c): $ echo "ag bh ci dj ek fl" | sed 's/\(a\|c\)./\1/' # Matches lines starting ...
1
vote
4answers
2k views

Batch renaming of files using regular expression in Unix

I have several thousand files of the form: [8-digit number]_[number I want]_S60491_I129111.dcm. I wish to remove everything except the number I want, and use that as its name. In Ruby, I can get to ...
0
votes
1answer
75 views

Why SED man -i option doesn't have description?

My Sed's man outputs this: Zero- or One- address commands = Print the current line number. a \ text Append text, which has each embedded newline preceded by a backslash. i \ ...
0
votes
4answers
292 views

How do I move a line in a file to the top from the command line?

I would like to move a path in a file to the top of the file. Each path is listed 1 per line. How do I move /someplace/2nd/ to the top using only the command line? /someplace/1st/ /someplace/2nd/ ...