I am trying to uncomment a line in html file using shell script but I am not able to write a sed command for this .
I have a line
<!--<url="/">-->
I need to uncomment this line using shell script
<url="/"/>
sed -i -e "s|'<!--<url="/"/>-->'|<url="/">|g" myFile.html
Any idea how to replace this comment?
Use :
sed -re 's/(<!--)|(-->)//g'
e.g:
echo '<HTML><!--<url="/">--> <BODY>Test</BODY></HTML>' | sed -re 's/(<!--)|(-->)//g'
Like this?
sed -i 's|<!--<url="/">-->|<url="/">|g' myFile.html
It's better to use single quotes because it prevents interpretation of everything including double quotes.
You need to escape(add backslash) before / character.Secondly, both crucial arguments should be separated with /, but not with |.Use the following line:
sed -i 's/<!--<url="\/">-->/<url="\/">/g' myFile.html
Related
So I wrote this sed commands to get .tsv files filtered (in this case) by chromosome 19. Unfortunatley i dont know how to get the Header for the tsv file as well. So far i only get headerless data. how should I modify my code?
wget https://www.dropbox.com/s/dataset.tsv.bgz -O temp.data.99.tsv.bgz
gunzip -c temp.data.99.tsv.bgz > temp.data.99.tsv
sed -n '/^19:/p' temp.data.99.tsv | sed 's/:/ /g' > finished_tsv_files/temp.data.99_Chr_19.tsv
rm temp.data.99.tsv
Replace
/^19:/p
with
1p; /^19:/p
to output first line, too.
While executing the below statement,
sed -l 's,`144_com`.,,q' [file_name_144_com.sql]
which is an attempt to remove the EXACT text (which in this case if the database name which needs to be removed for migration)
`144_com`.
from a MySQL dump file I get the error:
sed: -e expression #1, char 4: unknown command: `_'
I have attempted to escape the underscore with no luck. Any help would be greatly appreciated!
Using
sed -i 's/`144_com`.//g' 144_com_dev.sql
resolved the issue. -l was a typo, the trailing q was as well. Been a long day!
given a plain text document with several lines like:
c48 7.587 7.39
c49 7.508 7.345983
c50 5.8 7.543
c51 8.37454546 7.34
I need to add some info 2 spaces after the end of the line, so for each line I would get:
c48 7.587 7.39 def
c49 7.508 7.345983 def
c50 5.8 7.543 def
c51 8.37454546 7.34 def
I need to do this for thousands of files. I guess this is possible to do with sed, but do not know how to. Any hint? Could you also give me some link with a tutorial or table for this cases?
Thanks
if all your files are in one directory
sed -i.bak 's/$/ def/' *.txt
to do it recursive (GNU find)
find /path -type f -iname '*.txt' -exec sed -i.bak 's/$/ def/' "{}" +;
you can see here for introduction to sed
Other ways you can use,
awk
for file in *
do
awk '{print $0" def"}' $file >temp
mv temp "$file"
done
Bash shell
for file in *
do
while read -r line
do
echo "$line def"
done < $file >temp
mv temp $file
done
for file in ${thousands_of_files} ; do
sed -i ".bak" -e "s/$/ def/" file
done
The key here is the search-and-replace s/// command. Here we replace the end of the line $ with 2 spaces and your string.
Find the sed documentation at http://sed.sourceforge.net/#docs
I have several html files within subfolders which have a redundant link like:
<link rel="stylesheet" href="../demos.css">
I am trying to remove this line from all the html files using the following command in linux:
find -name '*.html' -exec sed --in-place=.bak 'demos.css' "{}" ;
But this gives me the following error:
find: missing argument to `-exec'
Yes of course I have checked all the solutions on Stackoverflow related to this but most of them are regarding a single file and the rest don't help. What am I doing wrong with this code?
find is missing starting path, sed is missing d command and you need to escape the semi colon in find command:
find . -name '*.html' -exec sed -i.bak '/demos\.css/d' '{}' \;
Or better:
find . -name '*.html' -exec sed -i.bak '/demos\.css/d' '{}' +
for i in `find /www/htmls/ -name "*.html" 2>/dev/null`
do
sed -i 's/^demos.css.*//' "$i"
done
try this please:
for i in `find /www/htmls/ -name "*.html" 2>/dev/null`
do
sed -i '/demos\.css/d' "$i"
done
I'm having an issue passing variables to a Bash script using QSub.
Assume I have a Bash script named example. The format of example is the following:
#!/bin/bash
# (assume other variables have been set)
echo $1 $2 $3 $4
So, executing "bash example.sh this is a test" on Terminal (I am using Ubuntu 12.04.3 LTS, if that helps) produces the output "this is a test".
However, when I enter "qsub -v this,is,a,test example.sh", I get no output. I checked the output file that QSub produces, but the line "this is a test" is nowhere to be found.
Any help would be appreciated.
Thank you.
Using PBSPro or SGE, arguments can simply be placed after the script name as may seem intuitive.
qsub example.sh hello world
In Torque, command line arguments can be submitted using the -F option. Your example.sh will look something like this:
#!/bin/bash
echo "$1 $2"
and your command like so:
qsub -F "hello world" example.sh
Alternatively, environment variables can be set using -v with a comma-separated list of variables.
#!/bin/bash
echo "$FOO $BAR"
and your command like so:
qsub -v FOO="hello",BAR="world" example.sh
(This may be better phrased as a comment on #William Hay's answer, but I don't have the reputation to do so.)
Not sure which batch scheduler you are using but on PBSPro or SGE then submitting with qsub example.sh this is a test should do what you want.
The Torque batch scheduler doesn't (AFAIK) allow passing command line arguments to the script this way. You would need to create a script looking something like this.
#!/bin/bash
echo $FOO
Then submit it with a command like:
qsub -v FOO="This is a test" example.sh