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

learn more… | top users | synonyms

1
vote
1answer
824 views

sed: can't read : No such file or directory

I use this as str_replace for every file in folder after unzipng archive in temp folder find "$tmp" -type f | xargs sed -i "s/${targetsubstring}/${newsubstring}/g" but I get this error: sed: ...
0
votes
1answer
28 views

SED basic substitutoin is not working

I am on ubuntu 12.04. Following expression: echo abcd123 | sed 's/\([a-z]*\).*/\1/' is supposed to get result as "abcd". But I am getting "abcd123". WHY?? Using following site as SED tutorial: ...
0
votes
2answers
194 views

Replace on Nth Occurrence

I have This Code sed '/Sometexts/ r newtext.txt' old.txt > new.txt This Replaces The String 'Sometexts' with the contents of text file newtext.txt but i want to replace on the 2nd ...
0
votes
2answers
99 views

Replace a Paragraph After a String

I have a text file with a lot of lines and paragraphs I want to replace a string with a line of string Example: Old Text File Sometexts New Text File Sometexts With Some Lines Paragraphs and ...
0
votes
2answers
86 views

split a textfile after each n matches to a new file using sed or awk

i tried to split a file in parts of n matches each. The file is just one line and the seperator is '<br>' foo<br>bar<br>.....<br> I just want to split the file in parts, ...
1
vote
1answer
116 views

Write text into first lines of every file

I want my web application to be free software, with a GNU license. I've read that I should add my name and the license in every file. I have a lot of files, so I guess that I could execute a command ...
-1
votes
1answer
25 views

Delete multiple lines with sed [closed]

HI I want to delete lines with this kind of text: lorem boringfunction("ads"); insum boringfunction("qwe"); lorem to lorem insum lorem
0
votes
1answer
41 views

Move numbers in a filename to the start

I have several files in a folder, with names in the form: SOMETEXT1 number SOMETEXT2.mp3, or SOMETEXT number.mp3. I want to rename these to number SOMETEXT SOMETEXT2.mp3, or number SOMETEXT.mp3. Using ...
3
votes
1answer
168 views

Replace special characters with set from Windows cmd

I need to replace the string "\\" (double quote backslash backslash double quote) with "" (double quote double quote). The following is an example of the data to be manipulated: ...
0
votes
3answers
330 views

Unix - Surround First Column of CSV with double quotes

I have data in the following format - 4,"abc" 8,"def" 9,"ghi" I want to surround the value of the first column by double quotes. "4","abc" "8","def" "9","ghi" How do I do that ?
1
vote
1answer
96 views

replace match to a back reference with a string in sed

I'm trying to come up with a sed script to modify the constructors in a couple hundred php files from php4 style to php5 style. I'm making some progress, but I'm having a problem with getting the back ...
0
votes
0answers
160 views

find and replace in PDF using sed and pdftk

I am doing a mass find and replace using sed and pdftk to find and replace a word in PDF files. When I run the following command, sed -e "s/word1/word2/g" test.pdf I get the following error, sed: ...
5
votes
1answer
98 views

Non-greedy regular expression to convert command tags

Background Consider the following text: There are three types of font families: serif, sans serif, and teletype. To switch between these families, use <cmd>rm</cmd> for serif, ...
2
votes
2answers
284 views

Bulk Rename Utility

I have been using Bulk Rename utility and I have been having some issues. I have some files named things like 664722.pdf,664762.pdf, and 664722-1.pdf that I need to rename. The problem is I have to ...
1
vote
2answers
60 views

Filtering input with sed (regex)

I'm having an issue with sed not returning what I expect when using a regex pattern to clean up some output from a mysql query. mysql -uroot -p -e 'SELECT `path` FROM db.media_gallery' | sed -n -r ...
1
vote
1answer
185 views

Using sed to enable .htaccess files in Apache config

I am trying to automate the provisioning of an Ubuntu Vagrant box with a Bash script. All is well, but I am having difficulty with configuring Apache to allow overrides from .htaccess files. In my ...
0
votes
2answers
52 views

converting '0'…'n' into '0' '1' up to 'n'

I'm processing a text file that has a few statements of the form '0'...'7' or '0'...'9' or even 'a'...'j' (the idiom '...' appears only in these structures) that I'd like to convert to ...
2
votes
1answer
67 views

How to do replace using sed only in one section of file

File looks like this: [section1] a=something [section_name2] a=something [section3] a=something How do I replace a=someother only in section_name2?
0
votes
2answers
39 views

Debugging output

I attempted to speed up an import of a large dataset with a folder full of .sql files ls -rS *.sql | parallel -j16 mysql -uusername -ppassword dbname "<" Shortly after running this I get an ...
0
votes
3answers
74 views

Pre-pending to an output line of `tail -f file` if its contents match another file

Trying to cram all of the following into the title was hard, so this is what I really mean: I am doing a tail -F access.log to watch an Apache2 log in realtime. The first thing on each line is an IP ...
1
vote
2answers
67 views

How do you get SED to replace only the first set of characters in a search expression

Basically I think this question is more one of regex than SED directly, but it’s SED I’m using, so that’s where I’m starting from. I’ve got a web.config configuration file for an ASP.NET 2.0 website ...
1
vote
1answer
2k views

Multi-Line Sed Replace

Consider the following text (incidentally, part of a MySQL dump): CREATE TABLE `table` ( `id` int(10) NOT NULL auto_increment, `name` varchar(100) NOT NULL default '', `description` text NOT ...
0
votes
2answers
89 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
107 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
234 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" ...
1
vote
5answers
418 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
60 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
254 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
85 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
76 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
114 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
59 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 ...
2
votes
2answers
609 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
80 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
103 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
47 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
98 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
269 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
259 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
651 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
1k 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
69 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 ...
1
vote
4answers
2k 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
92 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
50 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
127 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
149 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
96 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
1k 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\'.*$' ...