Extract values after the 2nd occurrence of _ (underscore) and before dot (.) in bash
<p>I have a file with some lines written in it in a temp directory. My goal is to extract the value between the 2nd underscore and the dot (.). For example, </p>

<p>Here is a sample of the contents of <code>filesample.txt</code>:</p>

<pre><code>--rwxr-x---                    235 2016-08-24 05:13 File_Name_2696553.txt
--rwxr-x---                   1274 2016-09-14 04:44 File_Name_2852659.xls
--rwxr-x---                   1802 2016-09-14 05:04 File_Name_2852992.pdf
</code></pre>

<p>What I have done is the following:</p>

<pre><code>cat ${tmp}filesample.txt | cut -b64- | awk -F"." '{ print $1 }'
</code></pre>

<p>This gives me the desired output. But, I think a better solution for this would be to have code that would look between the second underscore and the dot. </p>

<p>This way if the 7 digit number at the end of the contents of each line changes to 8 or more, I don't have to come back to my script and adjust it since <code>cut -b64-</code> is looking at the 64th position byte.</p>

<p>This is probably a basic question, I'm new to bash scripting.</p>