Copy the content from txt file and create a html file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Copy the content from txt file and create a html file
# 1  
Old 05-17-2019
Copy the content from txt file and create a html file

I have a txt file with a list of error messages in a xml tag format, and each error message is separated with a identifier(endresult).Need to split that and copy and create a new html file.Error message has some special character. how to escape the special character and insert my data into the file
Tried the below code
Code:
readsrror=`cat newfile.txt`
 echo "<html>" >>email.html
 echo "<body>" >>email.html
for i in $(echo $readsrror| sed "s/endresult/ /g")
do
    echo "<tr>" >>email.html
    echo "$i" >>email.html# only the tag is getting copied not the entire content.
    echo  "</tr>" >>email.html
done
echo "</body>" >>email.html
 echo "</html>" >>email.html


Last edited by DevAakash; 05-17-2019 at 05:18 AM..
# 2  
Old 05-17-2019
What exactly are you after?
# 3  
Old 05-17-2019
When copying the content to another file only single words gets copied. Not sure if I need to escape the special characters before copying
# 4  
Old 05-17-2019
Code:
$(echo $readsrror|

Try so
Code:
$(echo "$readsrror" |

--- Post updated at 11:45 ---

and
Code:
OFS=$IFS
IFS=$'\n'
for
...
done
IFS=$OFS

--- Post updated at 12:01 ---

Smilie I'm wrong

--- Post updated at 12:14 ---

one more
Code:
awk 'BEGIN {print "<html>\n<body>"} {print "<tr>" $0 "</tr>"} END {print "</html>\n</body>"}' newfile.txt

or
Code:
awk 'BEGIN {print "<html>\n<body>"} {print "<tr>" $0 "</tr>"} END {print "</html>\n</body>"}' RS='[[:space:]]' newfile.txt

# 5  
Old 05-20-2019
Thanks nezabudka , but these commands copy the entire content to my file in <tr> row,but I need to split the content from my base file and iterate through and copy each content into a <tr> tag.
Eg: Something like the below
Code:
read file
Split based on value <end>
for i to splitcount
<tr> $i</tr>
done

output:
Code:
<tr> errormessga [object not found :line 30 ]</tr>
<tr> Null pointer exceptions [no value available for the input :name ]</tr>

Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, output, and code segments.

Last edited by Don Cragun; 05-21-2019 at 02:13 PM..
# 6  
Old 05-20-2019
?
Code:
awk '...' $(<splitfile.txt)

--- Post updated at 08:26 ---

Code:
cat splitfile.txt

file1.txt file2.txt note.txt
end.txt

# 7  
Old 05-20-2019
May be so, sorry I don't quite understand
Code:
awk 'BEGIN {print "<body><html>\n<tr>"}; FNR == 1 && NR != 1 {print "</tr>\n<tr>"} END {print "</tr>\n</body></html>"} 1' $(<splitfile.txt)

This User Gave Thanks to nezabudka For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Convert Txt file to HTML table and email

Hi all I need help converting a text file into a html table in bash and I need to email this table. The text file looks like the below. Two columns with multiple rows. Top row being header. Application Name Application Status Application 1 Open Application 2 ... (2 Replies)
Discussion started by: hitmanjd
2 Replies

2. Shell Programming and Scripting

Change the file name and copy old file content to new file names.

Hi, I have a files in a directory as below :- ls -1 mqdepth-S1STC02 proc-mq-S1STC01 proc-mq-S1STC02 proc-mq-S1STC03 Whereever i have S1STC i need to copy them into new file with file name S2STC. expected output :- ls -1 mqdepth-S2STC02 proc-mq-S2STC01 proc-mq-S2STC02... (3 Replies)
Discussion started by: satishmallidi
3 Replies

3. Shell Programming and Scripting

Need to convert output.txt into html file

I have output.txt file generated through shell scripts which need convert in tabular format using html can you please help me output.txt Token State Date1 Date2 Description Name 34567 open 27/06/13 28/06/13 ... (5 Replies)
Discussion started by: vijay_rajni
5 Replies

4. Shell Programming and Scripting

create txt file form data file

File A.txt LL07 LL07_B_1 20 LL85 LL85_A_1 40 LL85 LL85_B_1 40 LL85 LL85_C_1 30 LL37 LL37_A_1 60 LL37 LL37_B_1 20 LL37 LL37_C_1 50 I want cretae diffrent tex file base of above file Should be threee text file LL07.txt LL85.txt LL37.txt Eaach text file have below data... (2 Replies)
Discussion started by: asavaliya
2 Replies

5. Shell Programming and Scripting

create txt file form data file and add some line on it

Hi Guys, I have file A.txt File A Data AK1521 AK2536 AK3164 I want create text file of all data above and write some data on each file. want Output on below folder /home/kka/out AK1521.txt Hi Welocme (3 Replies)
Discussion started by: asavaliya
3 Replies

6. UNIX for Dummies Questions & Answers

Help with Aligning the content of a txt file

Hello friends Please help me to display the content of a file in specific aligned manner. for ex. the content of the file may be >$TEST WELCOME HI HELLO UNIX SHELL SCRIPTING >$ I want to display the content like . TEST WELCOME HI HELLO ... (18 Replies)
Discussion started by: rajmohan146
18 Replies

7. UNIX for Dummies Questions & Answers

How to copy entire file content into another file being in last line mode of vi ?

How to copy entire file content into another file being in last line mode of vi ? ---------- Post updated at 10:07 AM ---------- Previous update was at 09:56 AM ---------- Got it : :1,30w file.txt (1 Reply)
Discussion started by: presul
1 Replies

8. Shell Programming and Scripting

Format txt file as html table

I have a short time to solve a problem, so I need some help. I've searched the forum, but I couldn't find a solution to my problem. I made a script to filter some text and now I have a new requirement to make it available as html table. Problem is that I more than one files with different set... (2 Replies)
Discussion started by: tetreb
2 Replies

9. Shell Programming and Scripting

Select some lines from a txt file and create a new file with awk

Hi there, I have a text file with several colums separated by "|;#" I need to search the file extracting all columns starting with the value of "1" or "2" saving in a separate file just the first 7 columns of each row maching the criteria, with replacement of the saparators in the nearly created... (4 Replies)
Discussion started by: capnino
4 Replies

10. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies
Login or Register to Ask a Question