-3
votes
0answers
81 views

Insert multiple lines into a file after specified pattern using bash shell scripting

I want to insert multiple lines into a file using shell script. Let us consider my input file contents are: input.txt: abcd accd cdef line web Now I have to insert four lines after the line ...
3
votes
2answers
129 views

How to make sed works with break lines from file?

I'm adapting this script to insert file's content into another file. This is what I have now: #!/bin/sh # Check if first and second parameters exist if [ ! -z "$2" ]; then STRING=$(cat $1) # ...
0
votes
1answer
30 views

Count length of letter string

I have a file that look like that (DNA sequence in fasta format): >sequence_name1 ATCGTGATNNNNNNNNAGTCGATCGGATTCT >sequence_name2 NNNNATGTNNATGTCCNNNNNNN I want to count the length of gaps, ...
1
vote
1answer
143 views

Bash script, cannote replace string in a file with escaped $ and &

I have creatd a shell script which takes a string as input. If the string contains '$' or '&', then I need to raplace those characters with '\$' and '\&'. I could done that with sed command. ...
0
votes
1answer
177 views

How to replace strings in file without regex?

I need to replace some strings in files (from command line) but I don't want to use sed -i because my string contains lots of funny characters which need to be correctly escaped. Is there a way to ...
1
vote
1answer
101 views

How to sed two words in a line and add before and after?

I was curious to know if there is a better way to sed two words and add a line before and after them. I learned how from grymoire but I wanted to know if there was a better way to do: #!/bin/sh ...
1
vote
1answer
105 views

How to use sed with this complex expression of special chars and ips?

How to use sed to replace for example this expression: connection = sqllite///keystone@10.10.10.51 with this expression connection = mysql://keystoneUser:keystonePass@10.10.10.51/keystone
1
vote
4answers
1k views

How to remove special 'M-BM-' character with sed

File: https://dl.dropboxusercontent.com/u/32919746/file I have file that was created by copying content from DOCX document with LibreOffice into text file. I have modified file with sed to remove ...
3
votes
2answers
169 views

How to batch organize files?

I have a directory with gigabytes (about 8gb) of small individual files. I want to organize them into directories by date. The date it was created is part of the filename. Here is an example of a ...
0
votes
1answer
182 views

search and replace inconsistency between vim and sed

Using the Ubuntu 12.04 and vim 2.22.0, why inside the vim I shall use: :9s/\d\+/1/ to change first digit of the mentioned line to 1, but couldn't be able to use the same with sed as : sed -i ...
1
vote
1answer
318 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 ...
0
votes
2answers
910 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 ...
1
vote
1answer
195 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 = ...
1
vote
2answers
203 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
1answer
411 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
162 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 {} \; ...
3
votes
3answers
2k 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. ...
17
votes
1answer
66k 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?
5
votes
2answers
8k 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
545 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
578 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 ...
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
4k 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 ...