- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need help for scripting..
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 07:26 AM
11-19-2003 07:26 AM
I would need to add a trailer record into a file generated by a script. The trailer record format should be "TRAILERDDMMYYYYNNNNNN"
where DD=current date, MM=current Month, YYYY=current year and NNNNNN=no of records in the file (excluding the trailor record).
For example, for a file created on November 17, 2003 with 645 records, the trailor should read as TRAILER17112003000645
Now, As you see in the example, the number of records could be any thing from 1 to 999999.
What should I do to create the trailor record in the proper format to fill all the 6 record fields. i.e, if the number of record is 589, then it should read as 000589
Appreciate your help!
Thanks,
Sailesh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 07:39 AM
11-19-2003 07:39 AM
Re: Need help for scripting..
filename=TRAILER$seqid
I don't know what you meen with records. Could you please clarify!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 07:43 AM
11-19-2003 07:43 AM
Re: Need help for scripting..
http://www.hpux.ws/merijn/caljd.sh
A. Clay Stephenson Wrote it.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 07:50 AM
11-19-2003 07:50 AM
Re: Need help for scripting..
Something like this might work. I wrote a little shell script named trail.sh. Just pass it the filename to generate the trailer record for as a parameter. The 'somefile' I used has ten lines in it:
>cat trail.sh
#!/bin/sh
# trail.sh
MYFILE=$1
typeset -Z6 LINES
MYLINES=$(wc -l $MYFILE | awk '{print $1}')
MYDATE=$(date '+%d%m%Y')
echo "TRAILER${MYDATE}${MYLINES}"
>./trail.sh somefile
TRAILER19112003000010
The trick to formatting your record count is to use the 'typeset' command. The -Z6 option tells typeset that the MYLINES variable will be six numeric characters, zero filled. You can read up on typeset in the sh-posix man page.
Have fun!
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 07:50 AM
11-19-2003 07:50 AM
Re: Need help for scripting..
Records are something like the number of entries in the file. simply
$ cat file_name |wc -l
There are 6 feilds allotted for the records.
and I need to fill all the six fields.even if the number is 589, the trailor should looks like TRAILOR`date`000589. My question is how do I add those zeros in it?
i.e, if the record is 589, then i need to add 3 zeros before 589. and if the record is 1589. then i need to add 2 zeros before 1589 to fill the vacant.
Thanks,
Sailesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 07:53 AM
11-19-2003 07:53 AM
SolutionRECORD_COUNT= `echo $RECORDS| awk ' { printf "%06d", $1 }'`
where $RECORDS is the unformatted count, and RECORD_COUNT would be the formatted number. So if $RECORDS = 589, $RECORD_COUNT would be 000589.
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 08:01 AM
11-19-2003 08:01 AM
Re: Need help for scripting..
the easiest way is to make use of the korn shell's capacities, e.g. try this example:
#!/usr/bin/sh
typeset -Z6 NUMBER
NUMBER=$(wc -l ./infile|awk '{print $1}')
echo $NUMBER
for further information, man ksh and look for typeset.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 08:11 AM
11-19-2003 08:11 AM
Re: Need help for scripting..
That works perfect!!
Thank you all once again.
Sailesh