Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.

To get the id value dynamically

Login or Register to Reply

Thread Tools Search this Thread
# 1  
To get the id value dynamically


I have .html file and need to get the id value based on the latest modified date from the html file.

output : 1456.

Thanks in advance

Here is the .html file

<h1> BI EI Team</h1>
<pre>ID   Last modified      Size</pre><hr/>
<a href="1456/">1456/</a>  01-Mar-2019 15:49    108MB
<a href="4561/">4561/</a>  28-Feb-2019 11:08    121MB

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-06-2019 at 06:41 AM.. Reason: Added CODE tags.
# 2  
Welcome to the forum.

Please become accustomed to provide decent context info of your problem.

It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, directory structures, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.

So - what have you tried so far?
Do you have GNU date available, or another version that allows a to-be-operated-upon-date parameter?

Last edited by RudiC; 03-06-2019 at 06:52 AM..
This User Gave Thanks to RudiC For This Post:
# 3  
Thanks Rudic,

I tried with below command but not accurate value am getting.

cat file.html |grep "<a href=" | head -2 |awk -F ">" '{print $2}

output : 1456/</a

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-06-2019 at 07:10 AM.. Reason: Added CODE tags.
# 4  
There is a closing single quote missing in your command pipeline, and the output will be the two lines with data from your input file:

Please be aware that none of the usual *nix text tools is well suited to handle *ml or similar data; any solution based on those will be crooked.

What is the essential criterion to identify the lines to extract from your html file? I used the field count (NF > 4) in this approach:
awk -F"[- :/]*" '
        {gsub (/<[^>]*>/, "")
!NF     {next
NF > 4  {print $4, $3, $2, $5, $6, $1
' file | LC_ALL=C sort -nr -k1,1 -k2,2Mr -k3 | head -1 | cut -d" " -f6

It depends on sort (GNU coreutils) to sort abbreviated month names.
This User Gave Thanks to RudiC For This Post:
# 5  
Hi ,

I achieved the result as my own. Is there any better way to do this.

cat file.html | grep "<a href=" | head -2 |awk -F ">" '{print $2}'| awk -F "/" '{print $1}'

# 6  
If you really want the id of the newest match, take RudiCs snippet. If you just assume that the first match is the newest, you can go simpler by using that:

awk 'match($0,/<a href="([0-9]+)/,res) {print res[1];exit}' data.html

If someone wants to use a parser for more robust operation, one can use this as a starting point:
xmlstarlet sel -t -v "/html/body/pre" data.html  | awk '/^\s*[0-9]+\// {print $1,$2}'

# output 

1456/ 01-Mar-2019
4561/ 28-Feb-2019

Note: I assume only gnu awk supports match(subject,pattern,array) Other variants of awk only support 2 parameter match like match(subject,pattern), which will cause a syntax error here.

Last edited by stomp; 03-06-2019 at 08:34 AM..
These 2 Users Gave Thanks to stomp For This Post:
Login or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Concatenation of different reports dynamically

Hi, I have the following reports that get generated every 1 hour and this is my requirement: 1. 5 reports get generated every hour with the names "Report.Dddmmyy.Thhmiss.CTLR" "Report.Dddmmyy.Thhmiss.ACCD" "Report.Dddmmyy.Thhmiss.BCCD" "Report.Dddmmyy.Thhmiss.CCCD"... (1 Reply)
Discussion started by: Jesshelle David
1 Replies

2. Shell Programming and Scripting

Dynamically split file

Hi guys, I have a file with 10000 entries (there are 2 columns. the first column contains the the product name and the second column contains the quantity of each product). I would like to split this file into 5 different files. I want the 1st entry to go to the fileA the 2nd entry to fileB... (3 Replies)
Discussion started by: coweb
3 Replies

3. Shell Programming and Scripting

Swap of fields dynamically

Dear Friends, I have file a.txt 1|2|3|4|5|6|7|8 a|b|c|d|e|f|g|h i am using the below code to swap the fields in file awk -F\| '{print $5,$1,$2,$3,$4,$6,$7,$8}' OFS=\| a.txt > output.txt output.txt 5|1|2|3|4|6|7|8 e|a|b|c|d|f|g|h The above command is working fine. I am... (4 Replies)
Discussion started by: i150371485
4 Replies

4. AIX

Geting a value dynamically from topas

Hi all, I got an idea to get a value (like Syscall or %comp details for example)dynamically from topas. Is there any way to do this. I guss there must be some door opened for this. I tried running topas and redirecting to a file but in vain. The idea is, script should run topas in... (4 Replies)
Discussion started by: jayadeava
4 Replies

5. Shell Programming and Scripting

Get Column location Dynamically

File Format U A 45 B N A 78 M M A 98 O Need to search for A in the file and whichever location is A is located need to get its next column i.e need to get 45 78 and 98 and put these values at end of file as new column Output U A 45 B 45 N A 78 M 78 M A 98 O 98 I can do... (7 Replies)
Discussion started by: dinjo_jo
7 Replies

6. Shell Programming and Scripting

Dynamically using mail host

Hi, Can we dynamically using mail host to send mail in UNIX script if it is not configured on UNIX box? Thanks, Paventhan (6 Replies)
Discussion started by: paventhan
6 Replies

7. Shell Programming and Scripting

set array name dynamically

Hi, I am trying to name a set of arrays dynamically named as @array_$i (The $i will mean that I obtain a set of arrays called: @array_1 @array_2 @array_3 etc. i tried various methods like @array_$i @{array_$i} etc. any ways to do this Thanks (4 Replies)
Discussion started by: esham
4 Replies

8. Shell Programming and Scripting

Dynamically locating a file

Hi, I have a requriement where in I need to install a s/w by executing the installable file through a script. The script currently contains the path of the installable file. I need to now update the script accordingly such tht it identifies the location of the installable file automatically and... (1 Reply)
Discussion started by: yoursdavinder
1 Replies

9. Shell Programming and Scripting

Spliting the file dynamically

i am creating the file , when this file reaches the size 2 GB, i need one message or fire (4 Replies)
Discussion started by: kingganesh04
4 Replies

10. Shell Programming and Scripting

getting value from field dynamically

how i do pass in field number when cutting, I tried to do this: but it says 11-1: not found (12 Replies)
Discussion started by: finalight
12 Replies

Featured Tech Videos