LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-24-2017, 02:27 PM   #1
eiefriends8
LQ Newbie
 
Registered: Apr 2017
Posts: 5

Rep: Reputation: Disabled
text files in folder and display them as links on html page using AWK


Hi,

I have a bunch of text files in folder and want to display them as links on HTML page using AWK code.

Thanks,
Kunal.
 
Old 04-24-2017, 02:35 PM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19.1 MATE
Posts: 8,016
Blog Entries: 5

Rep: Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861
Hi, eiefriends8, and welcome to LQ.

What have you tried so far?
 
Old 04-24-2017, 02:40 PM   #3
eiefriends8
LQ Newbie
 
Registered: Apr 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
I'm trying to list all the txt files in the directory with this command.
ls | grep -v '\.pdf'

My idea is when it lists all the text files, should be taken into a <li> tag and display them on the web page.
 
Old 04-24-2017, 03:12 PM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19.1 MATE
Posts: 8,016
Blog Entries: 5

Rep: Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861Reputation: 2861
Before you get into the business of actually populating the HTML page with data, your first move might be to write down an example of the target html that you're aiming for (do this with only two actual links to start off with to keep it simple). I'm assuming that you're going to use HTML5.

e.g.

Code:
<!DOCTYPE html>
<html lang="en">
<head> 
<title>Text file links</title>
...
Then save this to an .html file and test it by browsing to it.

Once you've achieved that, you can then start going through the stages of populating it.
 
Old 04-25-2017, 02:17 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,719

Rep: Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034
Do not use ls as a means of populating. Perhaps try a simple find command or if all in a single directory a glob would easily accomplish the task.
 
Old 04-25-2017, 03:49 AM   #6
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,169
Blog Entries: 3

Rep: Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061
Quote:
Originally Posted by hydrurga View Post
...
Once you've achieved that, you can then start going through the stages of populating it.
I usually just pipe my results into tidy and let it do the work of making proper HTML of it:

Code:
find ... | awk '...' | tidy -asxml > somefile.html
 
1 members found this post helpful.
Old 04-26-2017, 10:01 AM   #7
eiefriends8
LQ Newbie
 
Registered: Apr 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
Could you please help me out with the awk code.? I have a bunch of text files like 1.txt, 2.txt, 3.txt and display them as links on html page.
 
Old 04-26-2017, 10:05 AM   #8
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,169
Blog Entries: 3

Rep: Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061
Sure, but show what you've been able to figure out so far for awk so we have a starting point to begin with and so we can see which approach you wish to try.
 
Old 04-26-2017, 10:15 AM   #9
eiefriends8
LQ Newbie
 
Registered: Apr 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
find . -type f -name "*.txt" | awk '...' | tidy -asxml > somefile.html. I would like to know what to write in the awk code. As of now, find command displays all my text files. Now, I want to display the txt files as links on the html page.
 
Old 04-26-2017, 10:42 AM   #10
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,169
Blog Entries: 3

Rep: Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061
Ok. Here is something to work from:

Code:
awk '{ print $0 $0 }'
Since there is nothing before the braces { } every input line is selected. So what's between the braces happens each and every time.

See various tutorials for more information

http://www.grymoire.com/Unix/Awk.html
https://www.ibm.com/developerworks/library/l-awk1/

And don't forget the manual page for the version on your particular system.

Code:
man awk
 
Old 04-26-2017, 10:55 AM   #11
eiefriends8
LQ Newbie
 
Registered: Apr 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
That was awesome, but I want my all .txt files to be links. So when I click on the link, text file will open on the html page itself. I want to see the content of my txt files on the html page itself.
something like <li><a href=>textfile.txt</a><li>

I want to make my text file as a link. How can I write that in awk.

Last edited by eiefriends8; 04-26-2017 at 11:08 AM.
 
Old 04-26-2017, 11:36 AM   #12
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,169
Blog Entries: 3

Rep: Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061Reputation: 2061
Indeed. How can you write that in awk? Rummage through the two previous links and the one manual page and investigate how to use the print or printf functions.
 
1 members found this post helpful.
Old 04-26-2017, 11:44 AM   #13
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 12,501
Blog Entries: 9

Rep: Reputation: 3389Reputation: 3389Reputation: 3389Reputation: 3389Reputation: 3389Reputation: 3389Reputation: 3389Reputation: 3389Reputation: 3389Reputation: 3389Reputation: 3389
so what you need is a
Code:
<li><a href="filename.txt">filename.txt</a></li>
for every file found?
the whole list wrapped in something to make it a proper html document?
right?

edit:
oops, this was discussed already.
slight code correction, now i await development...

Last edited by ondoho; 04-26-2017 at 11:46 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Html that loads another html page on the same folder Ulysses_ Programming 6 12-01-2015 08:29 AM
Can wget extract links from a locally stored html page? LAPIII Linux - Software 1 11-12-2013 01:14 AM
looking for html to text renderer that keeps links onepostonly Linux - Software 2 09-24-2008 02:28 PM
Printing html page to pdf with links MikeyCarter Linux - Software 1 11-16-2006 06:20 PM
Program that can sort out multimedia links from html page walkingman Linux - Software 5 08-22-2006 06:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration