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

learn more… | top users | synonyms

0
votes
2answers
97 views

Trying to get example from Awk and Sed book to work on Ubuntu 13.04

I have been developing Windows Software for years. I am trying to branch out and learn Linux. It will really help with my new job. I have picked up the book, "Awk and Sed" 2nd Edition. I am ...
0
votes
1answer
136 views

Find a pattern in a line, and append that matched pattern to the same line

I'm trying to pull a job number out of notes listed in a csv, and then append that number to the end of the line, preferably through sed, awk, grep or perl (which I have installed in Cygwin. Here's a ...
1
vote
2answers
254 views

Change names in a column in bash

I have a tab-separated file in Linux that looks like this ~$ head list.tab "x" "1" "FUHGF.jnf.m22-1" "2" "HDFHFEY.gfs.d2-1" "3" "KJFGJF.fr.md2-1" "4" "SDFSDIB.gfd.rtl2-1" "5" "FGJFGOB.hgd.k2-5" "6" ...
2
votes
5answers
580 views

merge groups of lines with sed

I would like to merge each group of lines from file : <tr> <td >441</td> <td >S</td> <td >0,74</td> </tr> ...
1
vote
1answer
88 views

Delete all lines of text in the HTML file in addition to the first?

I have to rewrite a lot of HTML files, example: *--file1.html--* <p>text1</p><br> **<p>text2</p><br> ...<br> <p>text(n)</p>** *--file2.html--* ...
0
votes
1answer
63 views

Sed/Awk line double

I have a list like this. Bob Jim Steve Is there a way in bash to turn that into a list like this? <a href="http://example.com/Bob"> Bob <a href="http://example.com/Jim"> Jim <a ...
0
votes
1answer
391 views

how to replace unknown substring of line with sed

I want to replace a substring in a line, but I don't know what that substring is. I do know how the line starts though. For example, DNS1=[...to be replaced....]. I tried: sed -i ...
0
votes
3answers
93 views

How to use sed print the required content from each line?

The original file format: Nov 12 19:56:52 libra kernel: [ 1353.27355] WarningIN=em0 OUT=eth0 MAC=c8:1b:3c:fd:5D:e9:90:a9:8F:43:83:E3:15:0e SRC=222.171.89.16 DST=49.137.111.136 LEN=222 TOS=0x8C ...
0
votes
1answer
78 views

trying to extract two tables at a time from http files with 40 tables each

I have about 20 webpages. Each page has top banner navigation and then has information on up to 20 vehicles. There are 2 tables per vehicle. The logical flow is: page navigation, table 1 for ...
1
vote
1answer
128 views

Grep to find files that contain ^M When ^m dos2unix and sed or “grep -r $'\r' *” does not work

I use Cygwin and made a txt file using a Perl script. There is a ^M (Windows cariage return) added, and I have no idea how. How do I find ^M when normal ways (^m dos2unix and sed or "grep -r $'\r' ...
0
votes
2answers
65 views

Merge two separate sed expressions into one?

I'm reading the RealName from dscl for various users. Depending on the user, the output can be one of the following two: RealName: <name> Or: RealName: <name> So I have sed -e ...
3
votes
2answers
1k views

Multiple search and replace actions in one large text file

I have a big text file (about 2GB). I want to do five search and replace actions on the same file, and would like to do this in one command. Normally I use vim, open the file, do one replace action, ...
2
votes
3answers
109 views

sed regexp address case-insensitive matching

How to specify a sed regexp address which is case-insensitive? E.g., sed '/my-kw/d' But I want sed to remove lines with my-kw in any cases. Thanks
2
votes
3answers
108 views

sed, using line number

I want to replace some lines, but somehow I would like to add line number to the end of replaced line. s/display/echo print {LINENUMBER}/ input file: lorem ipsum display output: lorem ipsum echo ...
0
votes
1answer
48 views

Need to iterate through a list of files and append text at the first line of the files in th list on a Linux CentOS system

I need to be able to append the text <?php to the beginning of php files in a list. Thank you in advanced for the help.
0
votes
3answers
112 views

Possible to use more than one core with sed and bash?

I am looking to use more than one core when replacing values with sed in bash, is this possible?
3
votes
3answers
283 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
343 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
783 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
2k 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 ...
0
votes
2answers
81 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
4answers
3k 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
105 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
52 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
137 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
189 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
120 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 ...
0
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\'.*$' ...
2
votes
3answers
611 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
748 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
273 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
100 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
44 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"
3
votes
1answer
3k 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
79 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
2k 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
263 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
267 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
519 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
179 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
186 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
140 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
85 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
118 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
449 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
163 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
199 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
1answer
286 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
82 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 ...