pull date from header and append to all records

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers pull date from header and append to all records
# 1  
Old 07-06-2011
pull date from header and append to all records

I did some searches, but couldn't really find what I'm looking for. I have a file formatted as below:

BOF      ABC CO - XYZ COMM  DATA OF  07/05/2011
EBA00000001 sdfa rtyus uyml
EBB00000001 54682 984w3  
EBA00000002 mkiyuasdf 98234

I want to pull the date from the header record and add it to the beginning of each record.

07/05/2011BOF      ABC CO - XYZ COMM  DATA OF  07/05/2011
07/05/2011EBA00000001 sdfa rtyus uyml
07/05/2011EBB00000001 54682 984w3  
07/05/2011EBA00000002 mkiyuasdf 98234

Any suggestions?


Last edited by joeyg; 07-06-2011 at 04:46 PM.. Reason: Please wrap CodeTags around scripts and data
# 2  
Old 07-06-2011
awk 'NR==1{d=$9}{$0=d$0}1' file

# 3  
Old 07-06-2011
Hmmm....doesn't seem to like that...

[MBM10.0.1p6/test] # awk 'NR==1{d=$9}{$0=d$0}1' TEST.FILE.CONV
awk: syntax error near line 1
awk: bailing out near line 1
[MBM10.0.1p6/test] #

# 4  
Old 07-06-2011
What system are you using? Try this if it is Solaris:
nawk 'NR==1{d=$9}{$0=d$0}1' file

# 5  
Old 07-07-2011
That ran(I am on Solaris), but something still isn't quite right. The record length before adding the date is fixed 750 characters. I need the date added to every line, including the header, to making each record 758 characters fixed. Below is the beginning and end of the record of the first few lines in the file. You can see the date is not added to the beginning of the header record, which throws off the record length/wrapping of all subsequent records. The 'X' indicates the end of the record and should be in position 758 with the date added. Then each record after the header should start '20110705EB'. I can also see the 20110705 date added to each record(except the header), but it seems to be added somewhere in the middle of the record.


beginning of record:
00000000000│BOF      ABC NXP - ABC BILLING  DATA OF  07/05/2011 TO REMOTE N
00000000759│17FI AQ7 H73 AQ7015425  WINNER    JOHN R SMITH
00000001518│73 AQ7015425 00000001AQ7015425 USDWINNER    JOHN R SMITH
00000002277│26  STETZ     IRA FBO   JOHN SMITH            ABC LLC AS CUSTOD

end of record:
00000000000│                                                           XEBB00000
00000000759│                                                 XEBB000000017FI AQ7
00000001518│                                       XEBB000000027FI AQ7 JC7 AQ700
00000002277│                             XEBB000000027FI AQ7 JC7 AQ7002126 00000

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Append header with awk

I have to append the header (ie "START OF LINE") to a file only if there is data in it. Below command is showing header though there is no data in a file, can you suggest how to correct.. awk '{NR!=0} BEGIN{print "START OF LINE"}; {print}' file (3 Replies)
Discussion started by: JSKOBS
3 Replies

2. Shell Programming and Scripting

Compare files to pull changed records only

Hi, I am using Sun Solaris - SunOS. I have two fixed width files shown below. I am trying to find the changes in the records in the Newfile.txt for the records where the key column matches. The first column is a key column (example: A123). If there are any new or deletion of records in the... (4 Replies)
Discussion started by: Saanvi1
4 Replies

3. HP-UX

HP/UX command to pull file name/date based on date

HI, Can anyone tell me how to pull the date and file name separated by a space using the find command or any other command. I want to look through several directories and based on a date timeframe (find -mtime -7), output the file name (without the path) and the date(in format mmddyyyy) to a... (2 Replies)
Discussion started by: lnemitz
2 Replies

4. Shell Programming and Scripting

Command to pull date

I have one file with below entry. There are multiple entries, but for sample I used just three lines. my requirment is to create a script by which it will pull only those entries which modification time is greater than 2 weeks (or 15 days). if I run script today, it will compare date from today... (4 Replies)
Discussion started by: anshu ranjan
4 Replies

5. Shell Programming and Scripting

Copy header values into records

I'm using a shell script to manipulate a data file. I have a large file with two sets of data samples (tracking memory consumption) taken over a long period of time, so I have many samples. The problem is that all the data is in the same file so that each sample contains two sets of data.... (2 Replies)
Discussion started by: abercrom
2 Replies

6. Shell Programming and Scripting

Specific Header after every 30 records

Hi All, I have got a requirement. I have a source file, EMPFULL.txt and I need to split the data for every 30 records and place a Typical Header as below with system and page number too. 2012.01.03 Employee Dept Report 1... (6 Replies)
Discussion started by: srk409
6 Replies

7. UNIX for Dummies Questions & Answers

Need to pull Yesterdays Date...

I tried this and it works for the most part, but if the date is 20090301, it displays 20090300. YESTERDAY=$((`date +%Y%m%d` -1)) (2 Replies)
Discussion started by: cards0622
2 Replies

8. UNIX for Dummies Questions & Answers

Using awk (or whatever) to pull and append data in a new file

One of the fortunate things about posting in a "Dummies" forum is you probably aren't expecting a lot of out me... I'm trying to pull fields from two lines in the same file(s), and then append them together in a new file. So...I get a nice line-by-line of the first bit of data I'm looking... (6 Replies)
Discussion started by: Milano_EH3
6 Replies

9. UNIX for Dummies Questions & Answers

Append Header and Trailer

Hi everyone, I am new to Unix programming. My inquries is:- a) How to add a Header and Trailer in the set of data b) Include a number count of the data in the trailer The set of data only contained the information of 'Customer's Name' and 'Account Number'. I would like to add the Header... (2 Replies)
Discussion started by: balzzz
2 Replies

10. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies
Login or Register to Ask a Question