Get file names from string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get file names from string
# 1  
Old 07-29-2013
Get file names from string

Hello folks,
would like as for your help. I'm downloading list of files which need to be downloaded later.
Via curl I'm getting this output:
Code:
  
% Total    % Received % Xferd  Average Speed          Time             Curr.
                                 Dload  Upload Total    Current  Left    Speed
100  3142  100  3142    0     0   2313      0  0:00:01  0:00:01  0:00:00 3068k
                                                 <a href="/">[To Parent Directory]</a><br><br>            17 Apr 2013    13:41        89984 <a href="/CountryVolume/CountryMaturityStatus_20130417.xls">CountryMaturityStatus_20130417.xls</a><br>            22 Apr 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130422.xls">CountryMaturityStatus_20130417.xls</a><br>            29 Apr 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130429.xls">CountryMaturityStatus_20130429.xls</a><br>             6 May 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130506.xls">CountryMaturityStatus_20130506.xls</a><br>            13 May 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130513.xls">CountryMaturityStatus_20130513.xls</a><br>            20 May 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130520.xls">CountryMaturityStatus_20130520.xls</a><br>            27 May 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130527.xls">CountryMaturityStatus_20130527.xls</a><br>             3 Jun 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130603.xls">CountryMaturityStatus_20130603.xls</a><br>            10 Jun 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130610.xls">CountryMaturityStatus_20130610.xls</a><br>            17 Jun 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130617.xls">CountryMaturityStatus_20130617.xls</a><br>            24 Jun 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130624.xls">CountryMaturityStatus_20130624.xls</a><br>             1 Jul 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130701.xls">CountryMaturityStatus_20130701.xls</a><br>             8 Jul 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130708.xls">CountryMaturityStatus_20130708.xls</a><br>            15 Jul 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130715.xls">CountryMaturityStatus_20130715.xls</a><br>            22 Jul 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130722.xls">CountryMaturityStatus_20130722.xls</a><br>            29 Jul 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130729.xls">CountryMaturityStatus_20130729.xls</a><br>


From this I need extract only names of certain files like:
Code:
CountryMaturityStatus_20130417.xls
CountryMaturityStatus_20130429.xls
CountryMaturityStatus_20130506.xls

Just one note that text is in one long string including spaces (not in more lines).

Can anybody help??

THX
# 2  
Old 07-29-2013
Code:
awk -F'[<>]' '
        {
                for ( i = 1; i <= NF; i++ )
                {
                        if ( $i ~ /xls$/ )
                                F[$i]
                }
        }
        END {
                for ( k in F )
                        print k
        }
' filename

# 3  
Old 07-29-2013
Code:
$
$ cat -n f86
     1  % Total    % Received % Xferd  Average Speed          Time             Curr.
     2                                   Dload  Upload Total    Current  Left    Speed
     3  100  3142  100  3142    0     0   2313      0  0:00:01  0:00:01  0:00:00 3068k
     4                                                   <a href="/">[To Parent Directory]</a><br><br>            17 Apr 2013    13:41        89984 <a href="/CountryVolume/CountryMaturityStatus_20130417.xls">CountryMaturityStatus_20130417.xls</a><br>            22 Apr 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130422.xls">CountryMaturityStatus_20130417.xls</a><br>            29 Apr 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130429.x
ls">CountryMaturityStatus_20130429.xls</a><br>             6 May 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130506.xls">CountryMaturityStatus_20130506.xls</a><br>            13 May 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130513.xls">CountryMaturityStatus_20130513.xls</a><br>            20 May 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130520.xls">CountryMaturityStatus_20130520.xls</a><br>
  27 May 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130527.xls">CountryMaturityStatus_20130527.xls</a><br>             3 Jun 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130603.xls">CountryMaturityStatus_20130603.xls</a><br>            10 Jun 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130610.xls">CountryMaturityStatus_20130610.xls</a><br>            17 Jun 2013    05:00        89984 <a href="/CountryVol
ume/CountryMaturityStatus_20130617.xls">CountryMaturityStatus_20130617.xls</a><br>            24 Jun 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130624.xls">CountryMaturityStatus_20130624.xls</a><br>             1 Jul 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130701.xls">CountryMaturityStatus_20130701.xls</a><br>             8 Jul 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130708.xls">CountryMaturityS
tatus_20130708.xls</a><br>            15 Jul 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130715.xls">CountryMaturityStatus_20130715.xls</a><br>            22 Jul 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130722.xls">CountryMaturityStatus_20130722.xls</a><br>            29 Jul 2013    05:00        89984 <a href="/CountryVolume/CountryMaturityStatus_20130729.xls">CountryMaturityStatus_20130729.xls</a><br>
$
$
$ perl -lne 'print $1 while /<a href.*?>([\w.]+)<\/a>/g' f86
CountryMaturityStatus_20130417.xls
CountryMaturityStatus_20130417.xls
CountryMaturityStatus_20130429.xls
CountryMaturityStatus_20130506.xls
CountryMaturityStatus_20130513.xls
CountryMaturityStatus_20130520.xls
CountryMaturityStatus_20130527.xls
CountryMaturityStatus_20130603.xls
CountryMaturityStatus_20130610.xls
CountryMaturityStatus_20130617.xls
CountryMaturityStatus_20130624.xls
CountryMaturityStatus_20130701.xls
CountryMaturityStatus_20130708.xls
CountryMaturityStatus_20130715.xls
CountryMaturityStatus_20130722.xls
CountryMaturityStatus_20130729.xls
$
$

This User Gave Thanks to durden_tyler For This Post:
# 4  
Old 07-29-2013
Quote:
Originally Posted by durden_tyler
Code:
$
$ perl -lne 'print $1 while /<a href.*?>([\w.]+)<\/a>/g' f86
CountryMaturityStatus_20130417.xls
CountryMaturityStatus_20130417.xls
CountryMaturityStatus_20130429.xls
CountryMaturityStatus_20130506.xls
CountryMaturityStatus_20130513.xls
CountryMaturityStatus_20130520.xls
CountryMaturityStatus_20130527.xls
CountryMaturityStatus_20130603.xls
CountryMaturityStatus_20130610.xls
CountryMaturityStatus_20130617.xls
CountryMaturityStatus_20130624.xls
CountryMaturityStatus_20130701.xls
CountryMaturityStatus_20130708.xls
CountryMaturityStatus_20130715.xls
CountryMaturityStatus_20130722.xls
CountryMaturityStatus_20130729.xls
$
$


Excellent, that is exactly what I need.
Many thanks for quick help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding a string in a list of files, print file names

I'm interested in writing a report script using BASH that searches all of the files in a particular directory for a keyword and printing a list of files containing this string... In fact this reporting script would have searches for multiple keywords, so I'm interested in making multiple... (2 Replies)
Discussion started by: chemscripter904
2 Replies

2. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

3. Programming

Query to SELECT only Column Names that Contain a Specific String?

Hey Guys, I'm using SQuirreL SQL v3.5 GUI to fetch some data that I need for something I'm working on. I'm also using the IBM Informix Driver (*Version 3.5) to connect to the Database. What I want to do, if it's even possible, is to show all COLUMNS if they contain the word "Email". So in... (2 Replies)
Discussion started by: mrm5102
2 Replies

4. Shell Programming and Scripting

Grep string in files and list file names that contain the string

Hi, I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat. My OS is: SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise (8 Replies)
Discussion started by: apenkov
8 Replies

5. Shell Programming and Scripting

Extract all proper names from string with awk

I want to extract the proper names with awk from a very long string, like: õ(k): &lt;/span&gt;<br /><a something="pls/pe/person.person?i_pers_id=3694&amp;i_topic_id=2&amp;i_city_id=3372&amp;i_county_id=-1" target="_blank"><b>Gary Oldman</b></a> (George Smiley)<br /><a... (12 Replies)
Discussion started by: lyp
12 Replies

6. UNIX for Dummies Questions & Answers

command to extract sub-string out of file names

I have these files in a directory. It may have more class than the sample below: DEPT_CHEM101LEC_D_20110301.DAT DEPT_CHEM101LAB_D_20110301.DAT DEPT_BIO105LEC_D_20110325.DAT DEPT_BIO105LAB_D_20110325.DAT DEPT_CSC308LEC_D_20110327.DAT DEPT_CSC308LAB_D_20110327.DAT Is there way to extract out... (5 Replies)
Discussion started by: lv99
5 Replies

7. Shell Programming and Scripting

Evaluate string containing shell variable names

Hello, I have this: #!/usr/bin/ksh V1=ABC str="hello 123;${V1}" eval "echo $str" i get hello 123 /script.sh ABC not found However eval works if $str variable doesn't contain a semicolumn (eg if str="hello 123~${v1}" running the eval statement above would produce (2 Replies)
Discussion started by: endorphin
2 Replies

8. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

9. Shell Programming and Scripting

please help, find domain names in string

Hello, i have a file contains the information like below /home/username/domain.com/log/access /home/username/domain23.net/log/access /home/reseller/username/domain.com/log/access using a loop i can read every line of the file but i wants to extract domain name like(domain.com,... (3 Replies)
Discussion started by: eyes_drinker
3 Replies

10. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies
Login or Register to Ask a Question