Add HTML tags to file list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add HTML tags to file list
# 1  
Old 10-03-2014
Add HTML tags to file list

Hi there,

I am new to shell scripting and have been struggling with this example.

I have an input variable that looks like that:
FILELIST="100_*_123.txt"

that will produce a list of files if you use
ls ${FILELIST}

The output looks like 100_EN_123.txt 100_FR_123.txt

I am building HTML code out of it and need the list to be separated by html tags like this:

<p>100_EN_123.txt </p><p>100_FR_123.txt</p>

This is what I have so far except that it does not actually do the replacements I need:

Code:
echo "<p>"
ls ${FILELIST}| sed 's/\n/</p><p>/g'
echo "</p>"

I also searched and found a perl way of doing it but it gives an error that I don't know how to fix:

Code:
echo "<p>"
ls ${FILELIST}| perl -pe 's/\n/$1</p><p>/'
echo "</p>"

There must be something very simple that I am not getting. Please help if you can.
# 2  
Old 10-03-2014
Instead of echo, try using printf, so you can force the linebreaks where you want them:

eg:
Code:
for F in ${FILELIST};do
    printf "<p>$F</p>\n"
done

hth
# 3  
Old 10-03-2014
Try:
Code:
printf "<p>%s</p>" $FILELIST
printf "\n"

# 4  
Old 10-03-2014
Try
Code:
ls $FILELIST| awk '{for (i=1; i<=NF; i++) $i="<p>"$i"</p>"}1' RS= OFS=

# 5  
Old 10-03-2014
THANK YOU!

All solutions worked like a charm!

The solution suggested by Scrutinizer is the simplest I think.

I guess I need to read on printf command to understand how it works.

It was my first post and I did not expect 3 replies in so short time.

Thank you again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with moving list of data to 2nd column of HTML file

Hi Team, Can you help me with writing shell script to printing the list output to 2nd column in HTML file. (2 Replies)
Discussion started by: veereshshenoy
2 Replies

2. Shell Programming and Scripting

How to remove multiline HTML tags from a file?

I am trying to remove a multiline HTML tag and its contents from a few HTML files following the same basic pattern. So far using regex and sed have been unsuccessful. The HTML has a basic structure like this (with the normal HTML stuff around it): <div id="div1"> <div class="div2"> <other... (4 Replies)
Discussion started by: threesixtyfive
4 Replies

3. Shell Programming and Scripting

Add the html tag first and last line the file

Hi, i have 30 html files and i want to add the html tag first (<html>) and end of the line </html> tag..How to do it in script. Thanks, (7 Replies)
Discussion started by: bmk
7 Replies

4. 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

5. Shell Programming and Scripting

Remove html tags with particular string inside the tags

Could someone, please provide a solution to the following: I would like to remove some tags from the "head" of multiple html documents across the web site. They look like <link rel="alternate" type="application/rss+xml" title="Business and Investment in the Philippines"... (2 Replies)
Discussion started by: georgi58
2 Replies

6. Shell Programming and Scripting

Parsing HTML, get text between 2 HTML tags

Hi there, I'm quite new to the forum and shell scripting. I want to filter out the "166.0 points". The results, that i found in google / the forum search didn't helped me :( <a href="/user/test" class="headitem menu" style="color:rgb(83,186,224);">test</a><a href="/points" class="headitem... (1 Reply)
Discussion started by: Mysthik
1 Replies

7. Shell Programming and Scripting

Plain Text List to HTML List

Hello, I am trying to take a simple list (from echo, not a file) and turn it into a list with HTML codes. List item one. List item two. List item three. to <ol> <li>List item one.</li> <li>List item two.</li> <li>List item three.</li> </ol> The list is coming in via echo on... (4 Replies)
Discussion started by: QuestunAthority
4 Replies

8. Shell Programming and Scripting

Align Text within <p> Tags in a HTML file.

Hi All !!! I have an HTML file whose contents are as below: <html> <body> <title>This is a test file</title> <p>PLEASE ALIGN ME IN ONE LINE. TEXT....</p> <h2>This is a Test file</h2> <p>PLEASE ALIGN ME IN ONE LINE. TEXT....</p> </body> </html> (2 Replies)
Discussion started by: parshant_bvcoe
2 Replies

9. 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

10. Linux

How to remove only html tags inside a file?

Hi All, I have following example file i want to remove all html tags only, Input File: <html> <head> <title>Software Solutions Inc., </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor=white leftmargin="0" topmargin="0"... (2 Replies)
Discussion started by: btech_raju
2 Replies
Login or Register to Ask a Question