Shell script to pull certain fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to pull certain fields
# 1  
Old 10-06-2016
Shell script to pull certain fields

I/m a beginner so be easy. I have text files that live on an AIX server. The files come in and I've been charged with writing a shell script to email out that pulls the first date, and the last date of the file. I need to load these 2 dates into 2 separate variables. I can figure out the variables, but what I'm needing help on is what command to use and what syntax to pull the first and last date/time value for the 14th column in the text file. The columns are separated by a single tilde ~. This part is new to me, so I'd appreciate an experts assistance!

Thanks in advance,
Matt
# 2  
Old 10-06-2016
What have you tried so far? Can you provide some sample input data/desired output data?
# 3  
Old 10-06-2016
I haven't tried much in regards to printing this desired data. I'm hoping someone could tell me what command would be best to do this task, and possibly what parameters without being exact and doing it for me. Hope that helps.
# 4  
Old 10-06-2016
How are you to determine the "first date" and "last date" from these two files?

eg

"first date" could be:
field #14 from 1st record of file 1
minimum value of field #14 from file 1 and file2

"last date" could be
field #14 from last record of file 2
maximum value of field #14 from file 1 and file2
most recent modification time of file1 and file2
# 5  
Old 10-07-2016
In addition to what Chubler_XL has already said, if the dates to be used are based on the values in field #14 instead of being the dates on the 1st and last records in the file, you have to know the format of the date fields to determine how to perform the comparisons. And, if the values are to be extracted from the 1st and last data records in the file, we have to know if there are any header and/or trailer lines in the file.

This is why it is crucial that you give us a representative sample of the file(s) you will be processing.

Furthermore, you aren't at all clear about what tools are available for this project. You say the files you want to process are on a server. Will your script be run on that server while you are logged into that server? Will the files be located on one server while the script will be running on a different server?

The more details you hide from us, the less help we will be able to provide.
# 6  
Old 10-07-2016
Quote:
Originally Posted by Don Cragun
In addition to what Chubler_XL has already said, if the dates to be used are based on the values in field #14 instead of being the dates on the 1st and last records in the file, you have to know the format of the date fields to determine how to perform the comparisons. And, if the values are to be extracted from the 1st and last data records in the file, we have to know if there are any header and/or trailer lines in the file.

This is why it is crucial that you give us a representative sample of the file(s) you will be processing.

Furthermore, you aren't at all clear about what tools are available for this project. You say the files you want to process are on a server. Will your script be run on that server while you are logged into that server? Will the files be located on one server while the script will be running on a different server?

The more details you hide from us, the less help we will be able to provide.
---------- Post updated at 09:15 AM ---------- Previous update was at 09:14 AM ----------

Chubler and don,
Thanks so much for your reply. I'll upload a sample file today. Thanks a million.
# 7  
Old 10-10-2016
Here you go....i'm wanting to load a variable with the first and last column FirstExternalDateTime's values (last one would be 09032016011500PM) into an existing script. Please let me know if you have any ideas of how I can reference this particular file. See txt file attached.

Thanks in advance!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script to Group by Based on Multiple Fields in a file

Hi, I want to know if there is any simple approach to SUM a field based on group by of different fields for e.g. file1.txt contains below data 20160622|XXX1||50.00||50.00|MONEY|Plan1| 20160622|XXX1||100.00||100.00|MONEY|Plan1| 20160623|XXX1||25.00||25.00|MONEY|Plan1|... (3 Replies)
Discussion started by: cnu_theprince
3 Replies

2. Shell Programming and Scripting

How to get fields and get output with awk or shell script.?

I have a flat file A.txt with field seperate by a pipe 2012/11/13 20:06:11 | 284:hawk pid=014268 opened Locations 12, 13, 14, 15 for /home/hawk_t112/t112/macteam/qt/NET12/full_ddr3_2X_FV_4BD_1.qt/dbFiles/t112.proto|2012/11/14 15:19:26 | still running |norway|norway 2012/11/14 12:53:51 | ... (6 Replies)
Discussion started by: sabercats
6 Replies

3. Shell Programming and Scripting

Aligning output with null fields in shell script

Hello Gurus ! I have what probably amounts to a few simply changes to fix; however for the life of me I cannot seem to get it ti work. I need to align the output of my script (I am writing to a logfile)... here's the lines in my code: if then echo "NODE: $node" >> $logfile... (6 Replies)
Discussion started by: gvolpini
6 Replies

4. Shell Programming and Scripting

Script to pull hashes out of large text file

I am attempting to write a script that will pull out NTLM hashes from a text file that contains about 500,000 lines of data. Not all accounts contain hashes and I only need the ones that do contain hashes. Here is a sample of what the data looks like: There are thousands of other lines in... (6 Replies)
Discussion started by: chango77747
6 Replies

5. Shell Programming and Scripting

Shell script for validating fields in a file

Hi, I have not used Unix in a very long time and I am very rusty. I would appreciate any help I can get from the more experienced and experts in Shell script. I am reading one file at a time from a folder. The file is a flat file with no delimeters or carriage return. Col1 through col6 is... (5 Replies)
Discussion started by: asemota
5 Replies

6. Shell Programming and Scripting

Need script to pull multiple field from log file

I am hoping to get some help with a script to pull certain fields from a log file. User update (xx6xxx P) rpt (yy6yyy B) 2010/01/20 21:36:01.298 Remote client forward start streamid 85af 2010/01/20 21:36:01.307 rpt2 (ZZ6ZZZ G) rpt1 (YY6YYY B) urcall (CQCQCQ ) mycall (W1AW) user... (5 Replies)
Discussion started by: TedSD
5 Replies

7. Shell Programming and Scripting

Cat 114 files using grep or awk to pull muliple fields

Files xxxxxxx.txt ------------------------------------------------------------------------------------------------------------------------------------ Req.By: xxxxxxx WABUSH MINES - xxxxxx MINE (1001) Page: 1 Run on: 12/14/09... (4 Replies)
Discussion started by: sctxms
4 Replies

8. Shell Programming and Scripting

script to pull info from my email?

Hi, I need help writing a script that would pull info from an email inbox and add it to an Evolution Calendar. I'm pretty sure I can google the commands to add the info to the calendar. The part that I really need help with is getting the info from the email into the command. Basically for... (6 Replies)
Discussion started by: xinix
6 Replies

9. UNIX for Dummies Questions & Answers

Pull a file from a remote server through a shell script

Hi, I am writing a shell script to pull a file from a remote server (Let say its a windows based remote server). One of my criteria is to pull a file only if it is not empty. We have done a similar script to push a file from our end to a remote server and before pushing it we check for the... (2 Replies)
Discussion started by: sashankkrk
2 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question