Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Extract file names from file and set variable to 'highest' one Post 303009756 by SIMMS7400 on Tuesday 19th of December 2017 12:20:46 PM
Old 12-19-2017
Extract file names from file and set variable to 'highest' one

HI Folks -

I have a requirement where I need to scan a text file for a list of files.

The file, we'll called it, files.txt looks like such:

Code:
inbox/EBS/Client_GL_Detail_PBCS_112517_SEP2017.txt
 inbox/EBS/Client_GL_Detail_PBCS_112617_NOV2017.txt
 inbox/EBS/Client_GL_Detail_PBCS_112617_OCT2017.txt
 inbox/EBS/Client_GL_Detail_PBCS_112617_SEP2017.txt
 inbox/EBS/Client_GL_Detail_PBCS_120817_OCT2017.txt
 inbox/EBS/Client_GL_Detail_PBCS_121017_DEC2017.txt
 inbox/EBS/Client_GL_Detail_PBCS_121017_NOV2017.txt
 inbox/EBS/Client_GL_Detail_PBCS_121017_OCT2017.txt
 inbox/EBS/Client_GL_Detail_PBCS_121117_DEC2017.txt
 inbox/EBS/Client_GL_Detail_PBCS_121117_NOV2017.txt
 inbox/EBS/Client_GL_Detail_PBCS_121117_OCT2017.txt
 inbox/Client/Client_GL_Detail_PBCS_111417_SEP2017.txt
 inbox/Client/Client_GL_Detail_PBCS_111417_SEP2017.xls
 outbox/Client_2678.dat
 outbox/Client_2682.dat
 outbox/logs/Client_2954.log
 outbox/logs/Client_2955.log
 outbox/logs/Client_2956.log
 outbox/logs/Client_2957.log
 outbox/logs/Client_2958.log
 outbox/logs/Client_2959.log
 outbox/logs/Client_2960.log
 outbox/logs/Client_2961.log
 outbox/logs/Client_2962.log
 outbox/logs/Client_2963.log
 outbox/logs/Client_2964.log
 
 
 Total 489

I need to scan the file, searching for this string:

outbox/logs/Client_

Once found, I then need to understand if that string is suffixed with the highest numerical value on the end and then set that name (less the path) to a variable.
There will always be 4 digits and the 'highest' one is always the latest, which I need to extract.

I have done this on batch with ease but struggling here. I am using bash.

Thank you.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Variable assignment for file names.

I am trying to process error files in selected directories. I can count the files that are there and export the contents to a file for either emailing or printing. The next step is to move the files to a processed directory with the name changed to .fixed as the last extension. for file in... (2 Replies)
Discussion started by: jagannatha
2 Replies

2. Shell Programming and Scripting

File Names in a Variable in a loop

Hi All , I am having confusion in a shell script. Please guide me. I need to get multiple files (number of files vary time to time, file names are separated by '|') using FTP get from the remote server. Actually, i call the FTP function in a loop. At the last step, i need to move all the get... (3 Replies)
Discussion started by: spkandy
3 Replies

3. Shell Programming and Scripting

Replace variable names in text file with its value

Hi I have a text file (mytext.txt), the content of which is as following: My name is <@MY_NAME@> and my age is <@MY_AGE@> . Now i have another property file (myprops) which is as following: MY_NAME=abcdefgh MY_AGE=000000 I was wondering, how can i replace the tags of mytext.txt, with its... (1 Reply)
Discussion started by: vigithvg
1 Replies

4. 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

5. Shell Programming and Scripting

set a variable to be a list of file names

Hi all, I am trying to get a list of all the .tif images in my folder and set a variable that holds all the file names using C shell. What is the best way to do it? any help would be greatly appreciated. Yang (4 Replies)
Discussion started by: lionheartyoung
4 Replies

6. Shell Programming and Scripting

how to assign file names to array variable?

I wish to assign file names with particular extention to array variables. For example if there are 5 files with .dat extention in /home/sam then i have to assign these 5 files to an array. plz help me how to accomplish this. Thanks in advance. (4 Replies)
Discussion started by: siteregsam
4 Replies

7. Shell Programming and Scripting

Extract file names from a file

I'm trying to extract a list of each .cfg file name mentioned in a file. I've made some progress using sed, but I'm still not there. Any help would be appreciated. My input looks like this: 07:00:00.000 spn redo 08:04:36.200 CMD OBJ_INIT 08:04:37.200 CMD OBJ_INIT ... (8 Replies)
Discussion started by: jricks
8 Replies

8. 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

9. Programming

FORTRAN: Loop over variable file names

Hi guys I'm a beginner in fortran. So excuse me for my naivety, let me briefly describe what I was trying to do. I have let's say 2 files named reac-1 and reac-2. After opening these files I've to do some calculations, close these files and open the same files again in a loop. So my faulty code... (6 Replies)
Discussion started by: saleheen
6 Replies

10. Shell Programming and Scripting

Find matching file in bash with variable file names but consisent prefixs

As part of a bash the below line strips off a numerical prefix from directory 1 to search for in directory 2. for file in /home/cmccabe/Desktop/comparison/missing/*.txt do file1=${file##*/} # Strip off directory getprefix=${file1%%_*.txt} ... (5 Replies)
Discussion started by: cmccabe
5 Replies
GAMMU-SMSD-SQL(7)						       Gammu							 GAMMU-SMSD-SQL(7)

NAME
gammu-smsd-sql - gammu-smsd(1) backend using SQL abstraction layer to use any supported database as a message storage DESCRIPTION
SQL service stores all its data in database. It can use one of these SQL backends (configuration option Driver in smsd section): o native_mysql for gammu-smsd-mysql o native_pgsql for gammu-smsd-pgsql o odbc for gammu-smsd-odbc o drivers supported by DBI for gammu-smsd-dbi, which include: o sqlite3 - for SQLite 3 o mysql - for MySQL o pgsql - for PostgeSQL o freetds - for MS SQL Server or Sybase SQL CONNECTION PARAMETERS
Common for all backends: o User - user connecting to database o Password - password for connecting to database o Host - database host or data source name o Database - database name o Driver - native_mysql, native_pgsql, odbc or DBI one o SQL - SQL dialect to use Specific for DBI: o DriversPath - path to DBI drivers o DBDir - sqlite/sqlite3 directory with database See also The variables are fully described in gammurc documentation. SQL QUERIES
Almost all queries are configurable. You can edit them in [sql] section. There are several variables used in SQL queries. We can separate them into three groups: o phone specific, which can be used in every query, see Phone Specific Parameters o SMS specific, which can be used in queries which works with SMS messages, see SMS Specific Parameters o query specific, which are numeric and are specific only for given query (or set of queries), see Configurable queries Phone Specific Parameters %I IMEI of phone %P PHONE ID (hostname) %N client name (eg. Gammu 1.12.3) SMS Specific Parameters %R remote number [1] %C delivery datetime %e delivery status on receiving or status error on sending %t message reference %d receiving datetime for received sms %E encoded text of SMS %c SMS coding (ie 8bit or UnicodeNoCompression) %F sms centre number %u UDH header %x class %T decoded SMS text %A CreatorID of SMS (sending sms) %V relative validity [1] Sender number for received messages (insert to inbox or delivery notifications), destination otherwise. CONFIGURABLE QUERIES
All configurable queries can be set in [sql] section. Sequence of rows in selects are mandatory. All default queries noted here are noted for MySQL. Actual time and time addition are selected for default queries during initialization. delete_phone Deletes phone from database. Default value: DELETE FROM phones WHERE IMEI = %I insert_phone Inserts phone to database. Default value: INSERT INTO phones (IMEI, ID, Send, Receive, InsertIntoDB, TimeOut, Client, Battery, SignalStrength) VALUES (%I, %P, %1, %2, NOW(), (NOW() + INTERVAL 10 SECOND) + 0, %N, -1, -1) Query specific parameters: %1 enable send (yes or no) - configuration option Send %2 enable receive (yes or no) - configuration option Receive save_inbox_sms_select Select message for update delivery status. Default value: SELECT ID, Status, SendingDateTime, DeliveryDateTime, SMSCNumber FROM sentitems WHERE DeliveryDateTime IS NULL AND SenderID = %P AND TPMR = %t AND DestinationNumber = %R save_inbox_sms_update_delivered Update message delivery status if message was delivered. Default value: UPDATE sentitems SET DeliveryDateTime = %C, Status = %1, StatusError = %e WHERE ID = %2 AND TPMR = %t Query specific parameters: %1 delivery status returned by GSM network %2 ID of message save_inbox_sms_update Update message if there is an delivery error. Default value: UPDATE sentitems SET Status = %1, StatusError = %e WHERE ID = %2 AND TPMR = %t Query specific parameters: %1 delivery status returned by GSM network %2 ID of message save_inbox_sms_insert Insert received message. Default value: INSERT INTO inbox (ReceivingDateTime, Text, SenderNumber, Coding, SMSCNumber, UDH, Class, TextDecoded, RecipientID) VALUES (%d, %E, %R, %c, %F, %u, %x, %T, %P) update_received Update statistics after receiving message. Default value: UPDATE phones SET Received = Received + 1 WHERE IMEI = %I refresh_send_status Update messages in outbox. Default value: UPDATE outbox SET SendingTimeOut = (NOW() + INTERVAL locktime SECOND) + 0 WHERE ID = %1 AND (SendingTimeOut < NOW() OR SendingTimeOut IS NULL) Query specific parameters: %1 ID of message find_outbox_sms_id Find sms messages for sending. Default value: SELECT ID, InsertIntoDB, SendingDateTime, SenderID FROM outbox WHERE SendingDateTime < NOW() AND SendingTimeOut < NOW() AND SendBefore >= CURTIME() AND SendAfter <= CURTIME() AND ( SenderID is NULL OR SenderID = '' OR SenderID = %P ) ORDER BY InsertIntoDB ASC LIMIT %1 Query specific parameters: %1 limit of sms messages sended in one walk in loop find_outbox_body Select body of message. Default value: SELECT Text, Coding, UDH, Class, TextDecoded, ID, DestinationNumber, MultiPart, RelativeValidity, DeliveryReport, CreatorID FROM outbox WHERE ID=%1 Query specific parameters: %1 ID of message find_outbox_multipart Select remaining parts of sms message. Default value: SELECT Text, Coding, UDH, Class, TextDecoded, ID, SequencePosition FROM outbox_multipart WHERE ID=%1 AND SequencePosition=%2 Query specific parameters: %1 ID of message %2 Number of multipart message delete_outbox Remove messages from outbox after threir successful send. Default value: DELETE FROM outbox WHERE ID=%1 Query specific parameters: %1 ID of message delete_outbox_multipart Remove messages from outbox_multipart after threir successful send. Default value: DELETE FROM outbox_multipart WHERE ID=%1 Query specific parameters: %1 ID of message create_outbox Create message (insert to outbox). Default value: INSERT INTO outbox (CreatorID, SenderID, DeliveryReport, MultiPart, InsertIntoDB, Text, DestinationNumber, RelativeValidity, Coding, UDH, Class, TextDecoded) VALUES (%1, %P, %2, %3, NOW(), %E, %R, %V, %c, %u, %x, %T) Query specific parameters: %1 creator of message %2 delivery status report - yes/default %3 multipart - FALSE/TRUE %4 Part (part number) %5 ID of message create_outbox_multipart Create message remaining parts. Default value: INSERT INTO outbox_multipart (SequencePosition, Text, Coding, UDH, Class, TextDecoded, ID) VALUES (%4, %E, %c, %u, %x, %T, %5) Query specific parameters: %1 creator of message %2 delivery status report - yes/default %3 multipart - FALSE/TRUE %4 Part (part number) %5 ID of message add_sent_info Insert to sentitems. Default value: INSERT INTO sentitems (CreatorID,ID,SequencePosition,Status,SendingDateTime, SMSCNumber, TPMR, SenderID,Text,DestinationNumber,Coding,UDH,Class,TextDecoded, InsertIntoDB,RelativeValidity) VALUES (%A, %1, %2, %3, NOW(), %F, %4, %P, %E, %R, %c, %u, %x, %T, %5, %V) Query specific parameters: %1 ID of sms message %2 part number (for multipart sms) %3 message state (SendingError, Error, SendingOK, SendingOKNoReport) %4 message reference (TPMR) %5 time when inserted in db update_sent Update sent statistics after sending message. Default value: UPDATE phones SET Sent= Sent + 1 WHERE IMEI = %I refresh_phone_status Update phone status (battery, signal). Default value: UPDATE phones SET TimeOut= (NOW() + INTERVAL 10 SECOND) + 0, Battery = %1, SignalStrength = %2 WHERE IMEI = %I Query specific parameters: %1 battery percent %2 signal percent AUTHOR
Michal iha <michal@cihar.com> COPYRIGHT
2009-2012, Michal iha <michal@cihar.com> 1.31.90 February 24, 2012 GAMMU-SMSD-SQL(7)
All times are GMT -4. The time now is 01:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy