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

learn more… | top users | synonyms

1
vote
1answer
27 views

Is it possible to sed -i from a text file to another text file?

I'm coding a shell script on my Debian box and there's a line on the script that needs to delete some emails from a textfile that is full of emails, like this: sed -i ...
1
vote
3answers
119 views

How to select a section from a string in using bash

I have an array containing strings which consist of paths to files in the following format: /path/to/file/14561234545_50303.TXT I'm trying to select the section that is after the "1" but before the ...
4
votes
2answers
2k views

How append a string at the end of all lines?

I'm trying to add a string at the end of all lines in a text file, but i have a mistake... :( Example: I've this in a text file: begin--fr.a2dfp.net begin--m.fr.a2dfp.net begin--mfr.a2dfp.net ...
2
votes
3answers
1k views

Bash script, string not replaced correctly with escaped $ and & characters

I have created a shell script which takes a string as input. If the string contains $ or &, then I need to replace those characters with \$ and \&. I could done that with sed command. After ...
0
votes
3answers
35 views

How to add a character like # to the begining of the 1st nonblank line for several files?

I have a bunch of files, which I would like to use # to comment the 1st non-blank line, the files are not in good format, so there may be 1 or multiple blank lines before the line I want to comment. ...
0
votes
2answers
65 views

Redirect a cat command when using wildcards as input

I have the following command that takes a certain part of a file in the current directory, writes it to a temporary file, gets a part of another file one directory up, writes it to a temporary file ...
-1
votes
2answers
83 views

how to find number of substrings between delimiter? [closed]

I have the string following something(1)^^^something(2)^^^something(3)^^^ ... ^^^something(n) how to find number of something(s) in the string.
0
votes
1answer
90 views

iterating bash script for cycle in a file

I try to make this very simple bash program that must make the following operations: modify a file java n times: every time I must change a single word in a single line of the file (the line is 11) ...
1
vote
2answers
340 views

batch find/replace using sed or awk

In every file with filename matching pattern1 I want to search for lines which start with pattern2, and add some string in a new line above those matched lines. As a simple example suppose I'm ...
0
votes
1answer
33 views

How do I insert a line at a line of a file in sed for windows?

if i have a file half a pound of tuppenny rice half a pound that's the way the money goes pop goes the weasel And I want to insert a line "of treacle" at line 4. so it should be half a pound of ...
1
vote
4answers
895 views

How to split CSV files as per number of rows specified?

I've CSV file (around 10,000 rows ; each row having 300 columns) stored on LINUX server. I want to break this CSV file into 500 CSV files of 20 records each. (Each having same CSV header as present in ...
0
votes
2answers
172 views

Find and replace with sed, keep original line too

I have param1='123' I would like param1='123' param2=123 where 123 will change between the files I'd like to run this on. I can get param2 using sed -i "s/param1=\([0-9]\+\)/param2='\1'/g" ...
2
votes
4answers
7k views

Print line X lines before/after found line

I want to search for a particular string in a certain file. If I found the string, I also want to print the line X lines before (or after) that line. Can this with grep or awk, or do I need a ...
0
votes
1answer
141 views

Find number in string and replace it

I wrote C++ code and now I want to replace the number in a string by using shell scripts. The part that needs to be replaced: if (random<=90) How I can change the 90 from a shell script? I ...
1
vote
1answer
55 views

AWK does not work correctly in my system [duplicate]

i cant run this code because of an error awk 'BEGIN {x=0;y=0} { match($13,/([0-9]+)/,a); x = x + a[1]; match($12,/([0-9]+)/,b); y = y + b[1]} END {print "rxPackets:" x " txPackets:" y}' yourfile ...
2
votes
3answers
3k views

Extract URL from text with multiple URLs using sed

I have a string with a text and several URLs. How can I extract one specific URL (of a spoecific domain) with sed? For example, I have this: Text foo bar Text foo bar <br /><br /> ...
0
votes
0answers
32 views

Seperate one data file into 2 files

I would like to seperate 1 file into 2 or 3 files. (Normally I open .txt file, check second column and first, if it has different numbers and copy that data to Input a.txt:) ...
0
votes
2answers
58 views

Including " in a regular expression using sed on windows

I have: echo finally came. 34^"This is the account of | sed "s:[1-9][0-9]["]:<a name=\"top\">&</a>:g" and I need to get finally came. <a name="top">34"</a>This is the ...
0
votes
1answer
41 views

How to print statistics from lines in a file

I often find myself computing percentages manually after filtering through a log file to find the proportion of X or Y in it. Can this easily be achieved via common CLI tools?
0
votes
3answers
38 views

Almost-flattening a directory structure

I have a bunch of directories in a structure like this: -Music -Artist1 -Album1 -Album2 -Artist2 -Album1 -Album3 -Artist3 -Album2 -Album4 All the directories will ...
1
vote
1answer
3k 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
39 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
933 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
195 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
192 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
166 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
30 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
49 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
312 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
1k 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
178 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
355 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
213 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
609 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
83 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 ...
2
votes
1answer
382 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
53 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
190 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
47 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
97 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
96 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 ...
2
votes
1answer
6k 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
108 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
185 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
318 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
985 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
119 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
697 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
98 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 ...