awk command to omit trailer record in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk command to omit trailer record in a file
# 1  
Old 07-14-2014
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

My file has field separator as tab and record separator as Form Feed Line Feed or <FF><LF>

Is this an issue with the above separators? Please suggest

Last edited by bakunin; 07-14-2014 at 07:55 AM.. Reason: added ICODE-tags
# 2  
Old 07-14-2014
Provide us the sample input data and the output for your awk command
# 3  
Old 07-14-2014
Sample records

Code:
1       1       InPayANZ        12.0000         NZD                             NOW             011179099848025

2       2       InPayNonANZ     25.0000         NZD                             NOW             011179099848025

4       4       IP-OUR-NONANZ   20.0000         NZD                             NOW             011179099848025


Output

Code:
1       1       InPayANZ        12.0000         NZD  

2       2       InPayNonANZ     25.0000         NZD

Moderator's Comments:
Mod Comment edit by bakunin: please use CODE-tags, as required by the rules. Thank you.

Last edited by bakunin; 07-14-2014 at 07:54 AM..
# 4  
Old 07-14-2014
I am not sure if your data really contains so many empty lines, maybe you need to adapt this a bit:

Code:
sed -n '$ !p' /path/to/infile > /path/to/outfile

I hope this helps.

bakunin
# 5  
Old 07-14-2014
Code:
awk 'NR>1{print prev} {prev = $0}' ORS='\n\n' RS= sam

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

awk command to retrieve record 23 and 89 from UNIX file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file?... (6 Replies)
Discussion started by: rakeshp
6 Replies

2. UNIX for Beginners Questions & Answers

awk command to retrieve record 23 and 89 from UNIX file

Hi Everyone, I am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file? Please let me know what is the awk command for this? Regards Rakesh (1 Reply)
Discussion started by: rakeshp
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. Shell Programming and Scripting

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. (15 Replies)
Discussion started by: Harimalyala
15 Replies

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

6. Shell Programming and Scripting

[Solved] awk command to read sequentially from a file until last record

Hello, I have a file that looks like this: Generated geometry (...some special descriptor) 1 0.56784 1.45783 -0.87965 8 1.29873 -0.8767 1.098789 ... ... ... ... Generated geometry (....come special descriptor) ... .... ... ... ... ... ... ... and... (4 Replies)
Discussion started by: jaldo0805
4 Replies

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

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

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

10. Shell Programming and Scripting

using awk to omit certain characters

I have a file called file.txt with multiple lines in them. I'm trying to remove the first 2 characters and the last 2 with awk. '.batman') '.superman') '.dragonheart') .'superduper') I tried doing the following and able to get rid of the first two characters. How do I remove the trailing... (5 Replies)
Discussion started by: zerofire123
5 Replies
Login or Register to Ask a Question