The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Hidden control characters in a Unix Text File! kewl_guy Shell Programming and Scripting 6 1 Week Ago 10:09 AM
Control character in a file cursive UNIX for Dummies Questions & Answers 5 04-25-2007 10:40 PM
Control saving file by type saswerks UNIX for Dummies Questions & Answers 4 02-15-2005 12:47 PM
how can I create a dos file in sco unix? fresh SCO 2 03-29-2004 08:09 AM
unix process control nicko Filesystems, Disks and Memory 2 05-16-2002 04:39 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-05-2006
Registered User
 

Join Date: Jun 2006
Posts: 39
Stumble this Post!
Exclamation create control file in UNIX

UNIX gurus:

Following is what I am trying to do:

I need to create a control file for another file that I am creating. The information needed in the control file is the date in YYYYMMDD format and then the number of records in the other file right justified and lpadded with spaces of 20.

So say I have a file a.dat and it has 200 records.
I need to create a control file a.ctl having the following data.

20060605 200

I can only use UNIX commands as I am not allowed to use any scripts. I know date +'%Y%m%d' will give me the date in YYYYMMDD format and wc -l <filename> would give me record count but how would I go about piping the output of the above to one control file?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-05-2006
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,243
Stumble this Post!
What did you try? What shell are you using? This is bash, but should also work in ksh...
Code:
printf '%s%20s\n' $(date '+%Y%m%d') $(wc -l < a.dat) > a.ctl
Reply With Quote
  #3 (permalink)  
Old 06-06-2006
Registered User
 

Join Date: Jun 2006
Posts: 39
Stumble this Post!
Brilliant!! Thanks man it works!!

Im using ksh. i had tried a combination of cut, wc -l and date...but couldnt get it to work like u have. Could you explaina little bit more of what the above is really doing.
I am not able to figure out what the %s20s\n is doing?
Reply With Quote
  #4 (permalink)  
Old 06-06-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,846
Stumble this Post!
%s%20s

This is a format string - it tells how to format the arguments to printf
%s = a string
%20s = a string 20 characters long padded to 20 characters.

man printf
Reply With Quote
  #5 (permalink)  
Old 06-06-2006
System Shock's Avatar
Registered User
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 378
Stumble this Post!
Quote:
Originally Posted by alfredo123
I can only use UNIX commands as I am not allowed to use any scripts

... out of curiosity, why is this?
A script is nothing but a series of unix commands.
Reply With Quote
  #6 (permalink)  
Old 06-06-2006
Registered User
 

Join Date: Jun 2006
Posts: 39
Stumble this Post!
Quote:
Originally Posted by System Shock
... out of curiosity, why is this?
A script is nothing but a series of unix commands.
Its just the way the standards have been set. They dont want me creating any scripts on the box.

Thanks everyone.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0