Identify Trailer record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Identify Trailer record
# 1  
Old 04-30-2015
Identify Trailer record

Hello,

My script has a trailer record(TR).

Now I need to implement a logic, if TR is missed on the file it should generate me an email stating TR was not on the file..

Kindly help.
# 2  
Old 04-30-2015
Please provide an example of your script's trailer record
# 3  
Old 04-30-2015
.... and a sample of other records so that we can clearly identify what is acceptable.

If you simply want to check that the last line starts TR that is easy (when you know how) but if the requirement is more complex it might take some thinking.


Regards,
Robin
# 4  
Old 04-30-2015
yes I simply want to check if last line has TR or not..

Currently my file is as below. Hence if last line has TR then no issues but if it do not then it should generate a email to me stating TR was missing on the file
Code:
1|xyz
1|123
2|abc
2|456
TR| total records



Moderator's Comments:
Mod Comment Please wrap all code, files, input & output/errors in CODE tags
It makes them easier to read and preserves critical multiple spaces, as that can be very important.

Last edited by rbatte1; 04-30-2015 at 01:46 PM.. Reason: Added CODE tags
# 5  
Old 04-30-2015
Try
Code:
[ $(tail -1 file | cut -d\| -f1) == "TR" ] || echo mail something

# 6  
Old 04-30-2015
I guess this might work too:
Code:
tail -1 file | grep ^TR || echo mail something

gn8
# 7  
Old 05-07-2015
Can you guys explain along with if statement, I tried the below

if [ $(tail -1 file | cut -d\| -f1) == "TR" ]
then
echo "Trailer record is missing on the file" | mailx -m -s "Trailer record missing" a_b@x.com
fi

But this isn't working.

---------- Post updated at 05:50 AM ---------- Previous update was at 05:48 AM ----------

Sorry there is a typo

Can you guys explain along with if statement, I tried the below

if [ $(tail -1 file | cut -d\| -f1) != "TR" ]
then
echo "Trailer record is missing on the file" | mailx -m -s "Trailer record missing" a_b@x.com
fi

But this isn't working.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Identify empty file with null record

Hi Team, I have a file abc.dat which is a empty file. But it has null record in first line. I need to identify this unique file and handle it separately. scenario 1: abc/dw> wc abc.dat 1 0 1 abc.dat abc/dw> cat abc.dat abc/dw> scenario 2: abc/dw> wc pqr.dat 0 0 0 pqr.dat... (3 Replies)
Discussion started by: kmanivan82
3 Replies

2. Shell Programming and Scripting

Need code for updating second record to first record in shell scripting

Hi,, I have requirement that i need to get DISTINCT values from a table and if there are two records i need to update it to one record and then need to submit INSERT statements by using the updated value as a parameter. Here is the example follows.. SELECT DISTINCT ID FROM OFFER_GROUP WHERE... (1 Reply)
Discussion started by: Samah
1 Replies

3. UNIX for Advanced & Expert Users

Removing Header and Trailer record of a EBCDIC file

I have a EBCDIC multi layout file which has a header record which is 21 bytes, The Detail records are 2427 bytes long and the trailer record is 9 bytes long. Is there a command to remove the header as well as trailer record and read only the detail records while at the same time not altering... (1 Reply)
Discussion started by: abhilashnair
1 Replies

4. UNIX for Dummies Questions & Answers

Match sum of values in each column with the corresponding column value present in trailer record

Hi All, I have a requirement where I need to find sum of values from column D through O present in a CSV file and check whether the sum of each Individual column matches with the value present for that corresponding column present in the trailer record. For example, let's assume for column D... (9 Replies)
Discussion started by: tpk
9 Replies

5. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

6. Shell Programming and Scripting

awk command to omit trailer record in a file

I am trying to omit the trailer record in a variable width file I tried using awk 'NR >1 { print prev } { prev = $0 }' filename The above command is giving output but somehow it is trimming columns from the record. For example if my record has columns A,B,C,D The awk gives output as A,B,C ... (4 Replies)
Discussion started by: abhilashnair
4 Replies

7. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

8. Shell Programming and Scripting

How to add trailer record at the end of the flat file in the unix ksh shell scripting?

Hi, How to add trailer record at the end of the flat file in the unix ksh shell scripting can you please let me know the procedure Regards Srikanth (3 Replies)
Discussion started by: srikanth_sagi
3 Replies

9. Solaris

How to test the existence of trailer record

SunOS 5.10 Generic_142900-15 sun4v sparc SUNW,T5240 I have a script that needs to test a file for the existence of a trailer record. Is there a command and is a header and trailer differect record type? Thanks in advance (1 Reply)
Discussion started by: Harleyrci
1 Replies

10. Shell Programming and Scripting

csv file - adding total to a trailer record

Hi, I have a script which creates and modifies a csv file. I have managed to do everything I need to do apart from 1 thing. I need to append a trailer record to the file. I need this line to hold the total of an entire column of the csv file (skipping the 1st line which is a header). Can... (2 Replies)
Discussion started by: mcclunyboy
2 Replies
Login or Register to Ask a Question