create control file in UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers create control file in UNIX
# 1  
Error 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?
# 2  
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

This User Gave Thanks to Ygor For This Post:
# 3  
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?
# 4  
%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
# 5  
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.
# 6  
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.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #616
Difficulty: Medium
There is no separate char data type in Python.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script for creating Control file in UNIX

Delete ---- Original post, restored by mod after being deleted by abhilashnair ---- I have a requirement where, I need to create a control file which will have 3 columns in the header row as below: Filename Count Checksum This above control file has to contain metadata as above... (2 Replies)
Discussion started by: abhilashnair
2 Replies

2. Shell Programming and Scripting

Script to create the SQLLDR control file from Oracle table.

I need to create the shell script load the few 100 table using the SQLLDR. Need to generate the control file for each table using oracle table. table has "table names" and "column names" using this need create the control file. example table rows below table_nme column_nme DEPT ... (2 Replies)
Discussion started by: pimmit22043
2 Replies

3. Shell Programming and Scripting

Create a control file from Table definition

Hi Team, I need to create a control file with a pre-defined structure for a given table name. The table is in teradata. Ex: Table Name: TBL1 Table structure: create multiset table tbl1, no fallback, no before journal, no after journal, checksum = default, default mergeblockratio... (7 Replies)
Discussion started by: unankix
7 Replies

4. Shell Programming and Scripting

Request for advise on how to remove control characters in a UNIX file extracted from top command

Hi, Please excuse for posting new thread on control characters, I am facing some difficulties in removing the control character from a file extracted from top command, i am able to see control characters using more command and in vi mode, through cat control characters are not visible ... (8 Replies)
Discussion started by: karthikram
8 Replies

5. Shell Programming and Scripting

Create a File for Version Control

Hi , I have to create a file with 3 columns A,B,C. I have to read the column A,B values from a text pad. Where as Column a contains approximately 10 values and column B has 1 value which is constant. Column C is a version control column ,initially the value would be 1. (1 Reply)
Discussion started by: Inform123
1 Replies

6. Shell Programming and Scripting

control M character in unix file

in a file we are getting control character in a file , is there any way that they can be removed once we have the file for eg. BEGIN-PROCEDURE INITIALIZE ^M LET #row_count = 0^M ^M ^M (2 Replies)
Discussion started by: lalitpct
2 Replies

7. Shell Programming and Scripting

Extra control characters being added when I create a file using cat command

Hi, I am using Cygwin.I created a new file and type into it using cat > newfile. When I open this using vi editor, it contains loads of extra control characters. Whats happening? (1 Reply)
Discussion started by: erora
1 Replies

8. Shell Programming and Scripting

display all possible control characters from .xml file in unix

Hi, I have a .xml file in unix. We are passing this file through a xml parser. But we are getting some control characters from input file and XML parser is failing for the control character in file.Now I am getting following error, Error at byte 243206625 of file filename_$.xml: Error... (1 Reply)
Discussion started by: fantushmayu
1 Replies

9. UNIX for Dummies Questions & Answers

How to find the ^M(control M) character in unix file?

can any one say about command to find "^M" (Control M)characters in a unix text file. ^M comes when a file ftped from windows to unix without using bin mode. I need the command to find lik this, ex.txt: ------------------------------ ...,name,time^M go^M ...file,end^M... (5 Replies)
Discussion started by: prsam
5 Replies

10. Shell Programming and Scripting

Hidden control characters in a Unix Text File!

Can anyone seem to know how to find out whether a UNIX text file has 'hidden' control characters? Can I view them using 'vi' by some command line options? If there are control characters in a text file which are invisible/hidden.. then how do I get rid of them? Your intelletual answers are... (6 Replies)
Discussion started by: kewl_guy
6 Replies

Featured Tech Videos