Writing html to a file with echo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Writing html to a file with echo
# 1  
Old 04-13-2012
Writing html to a file with echo

Hi,

I'm having an issue with echo again. I keep getting errors and no file content with these commands in a script.

---------------------------------------------------
Code:
#!/bin/bash

WEBSITE=http://www.google.com    

touch test1.txt    

echo "replace("<body>","<body><iframe src='"$WEBSITE"' width=600 height=300 />");" > test1.txt    

exit 0

---------------------------------------------------

Any ideas?

Last edited by Franklin52; 04-15-2012 at 11:27 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 04-13-2012
Code:
echo "replace("<body

is attempting to redirect input to echo from a file called body.

You could use a heredoc:
Code:
[: /tmp] cat x.sh
#!/bin/bash

WEBSITE=http://www.google.com

cat > file1.txt << EOFILE
   replace("<body>","<body><iframe src='"$WEBSITE"' width=600 height=300 />");
EOFILE
[: /tmp] ./x.sh
[: /tmp] cat file1.txt
   replace("<body>","<body><iframe src='"http://www.google.com"' width=600 height=300 />");


Last edited by CarloM; 04-13-2012 at 01:50 PM.. Reason: added variable
# 3  
Old 04-13-2012
Once again

Amazed at the response. It works a treat!

echo can be nightmare!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Writing an HTML file in perl

I'm writing a perl script that writes an html file. use Tie::File; my ($dir) = @ARGV; open (HTML,">","$dir/file.html") || die $!; #-----Building HTML file--------------------------- print HTML "<!DOCTYPE html> <html> <head> <title>Output</title> <link... (3 Replies)
Discussion started by: jrymer
3 Replies

2. Shell Programming and Scripting

Writing HTML with variables from an array or other means

Hello! I wish to create a script that will automate the creation of HTML files... for example, if my HTML starts out containing: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>$TITLE</title> </head> I want to put that into something that I can read and write later on. My... (4 Replies)
Discussion started by: tntelle
4 Replies

3. UNIX for Advanced & Expert Users

Mutt for html body and multiple html & pdf attachments

Hi all: Been racking my brain on this for the last couple of days and what has been most frustrating is that this is the last piece I need to complete a project. There are numerous posts discussing mutt in this forum and others but I have been unable to find similar issues. Running with... (1 Reply)
Discussion started by: raggmopp
1 Replies

4. Shell Programming and Scripting

awk - writing matching pattern to a new file and deleting it from the current file

Hello , I have comma delimited file with over 20 fileds that i need to do some validations on. I have to check if certain fields are null and then write the line containing the null field into a new file and then delete the line from the current file. Can someone tell me how i could go... (2 Replies)
Discussion started by: goddevil
2 Replies

5. Shell Programming and Scripting

Problem with writing to output - awk, echo

Hello all, I wrote this command line for some calculation on my given input files based on another input file which is a txt file. while read BAM REGION; do samtools view $BAM $REGION | awk '{if ($2==0) print $0}' | wc -l >>log.txt; echo "$REGION"; done >> log.txt <regions.txt It takes... (4 Replies)
Discussion started by: @man
4 Replies

6. Shell Programming and Scripting

Removing all except couple of html tags from html file

I tried to find elegant (or at least simple) way to remove all but couple of html tags from html file, but all examples I found dealt with removing all the tags. The logic of the script would be: - if there is <li> or <ul> on the line, do nothing (=write same line to output) - if there is:... (0 Replies)
Discussion started by: juubuntu
0 Replies

7. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

8. UNIX for Dummies Questions & Answers

Writing to a file without echo it to the console !!!!

hi all, I am trying to write some message to a file using the following command. echo "${MESSAGE}" >&1 | tee -a ${File_name} can the same be done without using echo . I don't want the result to be displayed to the console. Can anyone guide me. Thanks in advance (6 Replies)
Discussion started by: amit_kv1983
6 Replies

9. Shell Programming and Scripting

cgi script to echo a html file

Hi, I'm learning some simple cgi scripting. I can make a script like this, so my browser shows "Hello World" /www/cgi-bin/name.sh --- #!/bin/sh MyName=World echo "<html> Hello $MyName </html>" --- What I'd like is to have a separate html and script files in the cgi folder so ... (1 Reply)
Discussion started by: Performer
1 Replies

10. UNIX for Dummies Questions & Answers

How do I extract text only from html file without HTML tag

I have a html file called myfile. If I simply put "cat myfile.html" in UNIX, it shows all the html tags like <a href=r/26><img src="http://www>. But I want to extract only text part. Same problem happens in "type" command in MS-DOS. I know you can do it by opening it in Internet Explorer,... (4 Replies)
Discussion started by: los111
4 Replies
Login or Register to Ask a Question