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

learn more… | top users | synonyms

0
votes
1answer
234 views

How to replace text strings by reading in list using sed

I'm trying to come up with a sed script to run from the shell. I need to be able to read in a list of UUIDs from an external file, which contains two columns origtexta replacementa origtextb ...
0
votes
3answers
38 views

Removing a pattern from text file

I have a file riddled with this kind of thing: -POEM- >> The big brown fox >> jumps over the >> lazy dog. The end. I want to get rid of "\n>>" and just turn this into a oneliner: ...
0
votes
1answer
62 views

Linux/Bash: Comment every line matching a pattern

sed is foreign to me, to say the least. I'd like to traverse a C project tree and comment out every line calling the function LogMsg(). Something that'd achieve the following: foreach: line within ...
0
votes
2answers
82 views

Replace string in string but not when its somewhere between double square bracket

I have a long string from mysql field containing the data of a mediawiki page. I have to replace a string in that mediawiki page but not when the string is in mediawiki link. The mediawiki link is ...
2
votes
2answers
90 views

How can sed find pattern in one field but append another(same row)

I have a text file that has comma separated values. Field1 has field that needs to be matched, but field two needs substitution based on the match. Example: A,C B,C Result: A,D B,C I'm guessing ...
0
votes
3answers
156 views

how can sed get patterns from a file

I have two files one holds a list of patterns, another need to be changed based on these patterns. So far I have been experimenting with cat patterns.txt| xargs -n1| sed ...
0
votes
1answer
45 views

How to encrypt the mail in unix?

I want to encrypt the mail as that will be containing the confidential information. There are no attachments. Please help in providing the steps to encrypt the mail. I have got the reference of How ...
0
votes
3answers
57 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
1answer
73 views

How to delete a line from a file that requires permission such as visudo using sed?

I want to add this command timestamp=20 at the end of visudo file which will increase the sudo time for 20 min. This way I'll be able to use my bash script to install many applications. After I am ...
0
votes
1answer
40 views

editing string using sed or grep

first of all please execuse my ignorance on UNIX. I am quite new. I have lot many sql files that contains following string ${DB_USERNAME}.${TABLE_NAME} Can anyone please tell me how could I change ...
0
votes
1answer
65 views

How to insert a comma after every 8th character of a line using sed

How do I insert a comma after every 8th character of a line that has alphanumeric characters including blanks?
3
votes
2answers
377 views

How to comment out multiple line matching a regex using sed or awk

I have a file that contains this: [...] location /static { ... multiple lines ... } [...] location /static/ { ... multiple lines ... } [...] And I want to get: [...] # ...
1
vote
2answers
59 views

Is there a way to print 2 lines (if any) before and after a target or print a placeholder if not?

I'm not native english speaker so I hope to be clear. I know about grep -C 2 "TARGET" inputfile to select 2 rows before and after the row of the TARGET, but I'm not able to use it to manage my ...
1
vote
1answer
26 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
90 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 ...
3
votes
2answers
420 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
4answers
598 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
32 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
53 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
63 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
72 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
230 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
24 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
440 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
115 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
2k 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
106 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
43 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
1k 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
56 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
29 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
29 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
2k 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
34 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
423 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
139 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
124 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
129 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
27 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
43 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
215 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
747 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
122 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
216 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
130 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
410 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
71 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
257 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 ...