Sed is known as a Stream Editor in that it can carry out various filtering and/or transforming functions on standard input or on user specified files.
1
vote
1answer
94 views
Tell sed to make changes but those starting with a specific string in 8th to last line
Here again with another problem with sed.
As the title says, I want sed to change lines starting at the 8th line to the end, but only lines which start with <b>.
I have code all ready and ...
1
vote
1answer
46 views
Change a string keeping some text as it is using sed
I have got another problem here with SED. I wanna add some text to a string but with out changing a particular word which varies with every line. Or wrap a code on a string keeping it as it is.
...
2
votes
1answer
48 views
Change specific lines using sed
I have a html file and i want to edit from 8th line till next to the last line i.e no changes to 1-7 and the last line with sed utility.
Example:
line 1 <i>some text<i>
line 2 ...
1
vote
3answers
42 views
Print text between two XML tags
Consider the following excerpt from a large XML file:
...
<serverName someKey="false" anotherKey="0.05" thirdKey="0.04">
<default>blah.blah.blah</default>
<region ...
1
vote
1answer
29 views
sed does not work
I tried to use the sed command to do some text replacement,
sed -i 's/port=\"8080\"/port="\8000\"' /opt/apache-tomcat-7.0.37/conf/server.xml
But I meet this error:
sed: -e expression #1, char 9: ...
4
votes
2answers
44 views
Print text file every three line start at 2nd line
I have done it with simple loop to count and print through.. How can I do it in bash scripting with program such as sed,awk ?
2
votes
1answer
39 views
Need help in SED and AWK
I have a file "list" as following:
main.c getname 25
main.c getage 36
util.c namecheck 123
The above has first string file name, second function name, and third line no.
I want to:
Open the ...
3
votes
3answers
281 views
How to run Ubuntu without GUI in Virtual Box?
I have a Windows XP laptop, in which I run VirtualBox with the latest Ubuntu, my hardware is little old, so running the latest version of Ubuntu inside Virtual box is kind of a hassle, very slow ...
6
votes
3answers
179 views
Replacing dots (.) in sed
I have a string of text:
" . . ."
that is
space dot space dot space dot
I am trying to replace all occurence of this string in text file to
"..."
that is
dot dot dot
I was trying to ...
0
votes
2answers
163 views
Inserting variable into sed command in bash script
I have text file similar to this:
Some-text
Keyword
Some-text
Some-text
Keyword
Some-text
Keyword
Keyword
I want to replace every "Keyword" with "number.extension" where number is 1 at first ...
2
votes
5answers
103 views
sed/awk make lines starting with lower characters be merged to previous line
Here is what I have
This
is
a
sample
text
How
to
do
it
?
I need the output to be:
This is a sample text
How to do it ?
In addition, how can I achieve the same with:
This
is
a
sample
text
How
...
1
vote
0answers
41 views
sed/awk - remove all tags except only two tags and plain texts
here is a sample for my text file:
<w:r><w:t>
<w:r w:rsidR="00D171FD">
<w:t></w:t>
</w:r><w:r>
<w:t xml:space="preserve">
This is a sample text ...
1
vote
1answer
55 views
Configure Fail2Ban with bash script
I'm trying to configure the /etc/fail2ban/jail.local config with an bash script. I was thinking to use sed and regular expression to change the sections I need.
sed -i "s/^bantime = 600/bantime = ...
2
votes
2answers
142 views
how to remove two forward slashes in a comment with sed
I have a configuration file and I want to replace a line containing a specific string, lets say test :
file.conf
aaa
bbb
ccc
// test
ddd
// test
My line of code is not working, I'm new to sed.
...
1
vote
2answers
89 views
How to replace an atypical pattern in a text file using sed
I have an MRTG configuration file containing lines starting with the word "Target". Now in such lines there is a pattern starting with the character "#", and ending with character ":".
A sample line ...
2
votes
1answer
60 views
How to replace primary key in MYSQL using SED
I need to replace the pattern: \(d+, to (. How can I do that?
Because when I exported db I need to remove the id column which is auto increment.
INSERT INTO `users` VALUES (22,'xxx@gmail.com'
...
1
vote
1answer
130 views
How do you use sed to edit a CSV file?
I have a CSV file like this:
hostname1 | role1 | environment | tag,list | |
hostname2 | role2 | environment | tag,list,longer | |
hostname3 | role3 | environment | | |
I need a sed expression that ...
1
vote
2answers
74 views
how to reverse the lower case characters in word using only sed
Reverse every word of a line using sed
Description
-----------
The job to do is reversing every word of a line.
that a word is a sequence of lowercase alphabets
Raw Input
...
0
votes
2answers
218 views
Stdout string manipulate, delete all after a word per line
My string look like this..
foo<..............................
bar</............................
I want to pipe for output as
foo
bar
Delete all characters after a first < found each ...
1
vote
1answer
210 views
how to execute for loop with sed in terminal
I want to execute the for loop with sed command, and is getting an error for the same
for i in <comma-separated server name list>;do "command";echo $i;done
where command=sed '/^$/d' ...
1
vote
1answer
100 views
Custom status Byobu
#! /bin/sh
echo "$(byobu ls|grep attached)"|sed 's/\([a-zA-Z0-9][a-zA-Z0-9]*\).*/\1/'
this is my script in ~/.byobu/bin/
refresh time is 1 second.
This shows the session name as the custom ...
2
votes
1answer
71 views
\t string with sed
I'm using sed to replace the string "\UPo" by the string "\textit{Old (User's preferences)}".
The command I'm using is:
find /home/rom/Desktop/nodeRemoval/report -name \*.tex -exec sed -i ...
1
vote
2answers
249 views
How to use sed to edit /var/log/apt/history.log in order to apt-get remove numerous installed packages?
After running these two commands:
sudo apt-get install ubuntu-desktop
sudo apt-get remove ubuntu-desktop
I am left with a glut of installed packages that I don't need/want on my Lubuntu install. I ...
0
votes
1answer
244 views
sed removes newline at EOF
I've tried using sed to replace an SELECT with BELECT in a file:
sed 's/SELECT/BELECT/g' add_pixel.sql | diff - add_pixel.sql
Gives me:
22c22
< BELECT MAX(ID) INTO max_id FROM pixels;
---
...
4
votes
3answers
129 views
Search and replace within files
I found the following awesome little script at link
$ find /home/bruno/old-friends -type f -exec sed -i
's/ugly/beautiful/g' {} \;
But I really do not understand the final bit
{} \;
...
1
vote
2answers
848 views
How do I combine all lines in a text file into a single line?
I want to get all lines in a text into one line. I'm a beginner at coding trying to learn by doing. I've spent four hours trying to solve this problem. I know there's a simple solution to this ...
1
vote
1answer
113 views
How do I catch exception from sed when trying to read a non-existent file and write a handler for it? [closed]
I am fetching specific value from a text file using sed into a variable.
If the file does not exist, an error will be printed:
sed: can't read filepath: No such file or directory
How can I catch ...
1
vote
0answers
88 views
What does this regex mean and why [closed]
$ sed "s/\(^[a-z,0-9]*\)\(.*\)\( [a-z,0-9]*$\)/\1\2 \1/g" desired_file_name
I apreciate it even if you only explain part of it or at lest structure it with words as in ...
1
vote
3answers
189 views
How can I make “sed” be specific when looking for a phrase
I am using "sed" to find and delete a phrase in a text file. It works great, but I can't seem to make it get specific. For example, this is my "sed" command:
sed -i 's/foobox.com//' ...
2
votes
2answers
489 views
Grep for contents between two markers with newlines
Just curious if there's a way I can show the output between two markers?
I was trying grep -r "<cron_expr>.*</run>" * but it doesn't seem to be returning as
expected. Which is to say its ...
3
votes
2answers
527 views
I cant get the most basic sed command to execute on command line
I feel like a total newb. Why does this not work?
$ echo foobar > textfile
$ sed /foo/bar/ textfile
sed: can't find label for jump to `ar/'
I've also tried sed "/foo/bar/" textfile and sed ...
1
vote
1answer
500 views
Using “sed” to find and replace a non atypical string
I need to use sed in the terminal (no other option, I'm afraid) and I need to find and replace all sequences of four or more digits (no white spaces) with a specific word "brad". I have tried and ...
0
votes
3answers
289 views
Filter results into a usable variable
I run the following command:
sudo iwlist eth0 scan
and get output that looks like this:
Cell 01 - Address: AB:CD:EF:12:34:56
ESSID:"name"
Protocol:IEEE 802.11g
...
-1
votes
2answers
403 views
How to replace line with 3 lines / add 2 before found / add 2 before 1 from end [closed]
File is:
#Welcome to the file
#this is a file and it ends on "exit 0"
#Here are unknown number of lines
exit 0
Needs to have these lines one after each other:
echo deadline > ...
1
vote
5answers
1k views
How to programatically remove empty new lines from a file?
I need to remove empty new lines from text file in terminal.
Example file
123
123
123
123
123
123
I've searched in google a bit but only solution found was sed '/^$/d' myFile > tt and it ...
3
votes
3answers
1k views
How to find text and replace that line if exists with terminal otherwise just append line to end
I want to put in sudo gedit /etc/sysctl.conf the one line vm.swappiness=10 which I sometimes change.
By default this line doesnt exist so I use echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf.
...
7
votes
1answer
27k views
how to use variables in SED?
I try the fallowing code and it does nothing
var1=QQ
sed -i 's/$var1/ZZ/g' $file
However this code replaces QQ with ZZ
sed -i 's/QQ/ZZ/g' $file
how to use variables in SED?
1
vote
1answer
3k views
How to escape file path in SED?
I would like to replace $fileWithPath in $file, however this not works because (I think) path is not escaped. how to escape it?
sed -i 's/${fileWithPath}/HAHA/g' $file
0
votes
2answers
269 views
Problem using `sed` to colorize `ls` output (Tenth back-reference `\10` not working)
I had asked this question a while back: Is it possible to colorize permissions-part of the output of ls?
While the accepted answer in that question is OK, I now want to do the same thing without ...
1
vote
2answers
471 views
how to use grep in a conditional search previous to a sed text replace command
I am trying to change the path in whole lot of m3u files.
I know I can do it with regexxer f.e. but I'm trying to learn bash.
This is the command I figured out, but it is not working.
grep -lr -i -e ...
1
vote
1answer
539 views
Read character encoding with sed
I'm trying to write a bash script to convert all special characters inside a file (é, ü, ã, etc) into latex format (\'e, \"u, \~a, etc). Usually, this stuff is really easy to do with sed, but I'm ...
7
votes
1answer
3k views
One line command for adding new items to com.canonical.Unity.Panel systray-whitelist
This is more of a how to use command line instruction question more than how to add items to the Unity notification panel.
I have to have a one line CLI to add a new item to com.canonical.Unity.Panel ...
2
votes
2answers
1k views
Sed problem in a Bash script
I'm having a problem using the sed command . I'm trying to write a bash script that does the following :
search for the line that contain :@
then save the line that contained :@ and replace it ...
2
votes
1answer
2k views
How can I remove the first line of a file with sed?
the following lines append the content of essay_i.txt to the end of essay1.txt;
touch essay1.txt
for (( i = 1 ; i <= 10 ; i++ )); do
sed '2p' essay_"${i}".txt >> essay1.txt
done
how should ...
1
vote
1answer
171 views
Adding quotes to a string in a file
I currently have an SQL file filled with insert statements in the form:
INSERT INTO
database.table(primary_key,
foreign_key, url_one,
url_two, int_one,
int_two, int_three) VALUES
...
