How to cat contents of text file to a table data or row
Does anybody know how to how to cat/pipe or print, (w/e works best) the output of a command, in this case a simple wc -l query directly to a table data or row?
What Im trying to do is print the output of a command to a table data box inside of an html table. So specifically. I need to display the line count of individual files and crontab that script or command so its updated regularly, automatically on the website. So I need the output ( in this example --> 123456 and no the output isnt static, it changes daily, so I cant simply print 123456 over and over, this is the whole reason it needs to be updated ) Ok so. wc -l somefile.txt 123456 And I need that to be dumped to a table within /var/www/index.html Which has a table in it, but this is the the specific <td> where the data needs to go, I have already added id= for this very reason This is what I need. <td id="target">123456</td> Thanks in advance, google isnt really bringing me what I need, so hopefully if this gets answered somebody else whos as stumped as me can find it in the future. |
Your post doesn't really explain your question very well, but it sounds like you have a file, /var/www/index.html, presumably existing on a web server, and you want this file to report how many lines are in, somefile.txt, that presumably exists somewhere on your web server's file system (you didn't give us a path).
I would say that just running some linux command to count the lines in somefile.txt and locate where to put it in the index.html file sounds a bit tricky, but maybe not for a BASH expert. Sadly, html files are usually not able to run server-side scripts unless you take special care to configure your web server to allow server-side code execution (e.g., server-side includes. If, instead of index.html, you wanted to use PHP instead, then you could write a bit of PHP code to check the size of the file dynamically when the page is requested and just echo the information in response to a page request. |
Well
Well all I need to do is have the output of wc -l on /var/www/somefile.txt be printed or cat or echo'd or w/e works best, into a specific table, which means, inserting it between two specific objects located in /var/www/index.html
The two objects are unique within the file, and as I mentioned, the output needs to be placed directly between these objects <td id="target"> and </td> so the desired result is that the output of wc -l /var/www/somefile.txt gets dumped to the html <td id="target">123456</td> ( well there are actually multiple </td> ending tags in the table, so thats not unique is it, but there is a unique id=" for each td I need this done for, Ive actually got about 23 different files that needs to have this done for, but all I need is one working example to replicate ) |
Quote:
The extra information is helpful, but you might want to be more specific: * does this only need to happen one time? If so, why not do it by hand? * does this need to be automated? If so, what is your means of triggering the process that does it? * does this need to happen in response to a webs server request so that it's always up to date? |
Perhaps
Perhaps it is not something either of us knows how to do, but it it can be done, and it isnt that complicated.
Which is precisely why I am hoping somebody will come along with a solution. It isnt difficult to execute a series of sed/awk/grep commands in series in a bash script. The trick is just figuring out precisely how to do it. |
If these are all just simple text files, assign the output of the "wc" command to a bash variable. Use that variable in a sed command to substitute the appropriate text. Test it then stick it in a loop.
Make sure your regex is sufficiently specific - especially be aware of regex greediness (multiple ">" per line for example). And I find it's usually best to use backreferences to contain the bits you want to retain. |
Quote:
Or you can just keep asking the original question... |
Quote:
Im definately open to any suggestions and certainly, very thankful. |
plz answer questions i posed before
Quote:
|
Have a one line file ONELINER.js since a javascript file can be included freely in plain html even.
Its content is got by echo 'document.write("<td id="target">' $(wc -l somefile.txt) '</td>")' > ONELINER.js This should create the one liner that can be included in the appropriate place in the script by> <script source=ONELINER.js></script> OK |
Quote:
So in your web page, you'd have a line like this pointing to your table at the point in the HTML file where you want the table to be inserted: Code:
<!--# include virtual="/my_table.html"--> SSI gets a bad reputation because it is very secure (with IncludesNOEXEC), very low maintenance, and very easy to set up. So while it gives you an excellent return on investment, it cuts into the revenue of consultants who profit on churn. They tend to be the ones you hear from in the trade press since they are numerous. Another option could be a simple shell script with a Here Document that produces the entire HTML document, including the table, whenever the table needs updating. I can appreciate that some fine folks use PHP and that there are many useful systems built with PHP, in spite of PHP itself which is acknowledged to be kind of a dumpster fire. More generally, PHP, Python, Perl, or Java Server Pages could be used, but any of them would be overkill if you are just inserting into a page or two. And client-side javascript has too many issues to address here. |
No need to hold back - say what you really mean ... :p
|
Quote:
Quote:
|
Quote:
Quote:
CaptainDerp, can you post an example of the HTML table you are working with? It helps to see as close to the exact spacing and line breaks as possible. You can remove sensitive information and post it between [code] [/code] tags. But do show which cell or row where you want the output from "wc" |
Quote:
|
All times are GMT -5. The time now is 12:21 AM. |