I receive notification files for different files. I want to extract the filename from these notification files which I would use in another process. The first 4 strings of the notification file will always be ignored. So the filename starts at the 5 position, can start with any character and ends at the .csv. The filename could be any length.
An example:
NotificationFile = 'NFT_PPF_STANDARD_1720156B_NBIRNans_DFT_TILT_EOF_FFP_20160619-10.csv_16062000352520'
NotificationFile = 'NFT_PPF_IMPULSE_172555A_Acc_Account_FFP_20160619-10.csv_16062000352520'
NotificationFile = 'NFT_PPF_IMPULSE_172555A_CRI_Position_FFP_20160619-10.csv_16062000352520'
The filenames respectively:
Filename = 'NBIRNans_DFT_TILT_EOF_FFP_20160619-10.csv'
Filename = 'Acc_Account_FFP_20160619-10.csv'
Filename = 'CRI_Position_FFP_20160619-10.csv'
I use the following command to extract the filename from the notification filename but it only works if the filename contains only 3 '_'s:
Extract = echo $NotificationFile | cut -d "_" -f5-8
# $NotificationFile is the NotificationFile above
# Extract should be equal to Filename
What is a general command I can use for any filename length?
$notificationFilecontain? Is it the name or the entire line you show? What exactly are you trying to extract? What can and what cannot change in the general case? Will there always be 5 fields at the beginning that you want to ignore? Can there be more? Or less?_, if so say so. You still haven't explained what is in the variable you echo. Is it theNotificationFile = 'NFT_P...that you show in your question? Is it only the part after the=? Is it something else? And how about the name? Ok, the first 4 (presumably "_" separated) fields must be ignored, but what comes afterwards? How many fields? Edit your question and explain exactly what you need.