Korne Script for format file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Korne Script for format file
# 8  
Old 02-21-2005
bhargav,

So those number 30, 20, 15 are the width of the field that you want it to be? like id has 30 characters, name has 20 character..and so on?
what if i want to have other things that are not on the original file in the new file also? Example:

file1, original file, have 4 colume : id, first name, last name, amount

i want the file 2 to be in the format:
--------------------------------------------------------------------------
V2
Uid lastname, firstname date school account amount00
--------------------------------------------------------------------------

Here is the actual output that i export form the MS Access (it is all in one line, with V2 on the very first line. id= 000702687, lastname=Adams, firstname=Abigail, amount= 200 (last one on the line, with extra 2 zero's)
Code:
V2
U000702687          Adams, Abigail                         01/01/10                                                                                                                          School Name Inc.                                                                                                                                                                   PA01001000100100PA01011010101101AD010010020000

(it is at certain column width, but it won't show that in here when i paste it in)
[Edit --- it will if you use code tags. I have added them. -- Perderabo]

Thanks

CT

Last edited by Perderabo; 02-21-2005 at 06:14 PM.. Reason: Add code tags for readability
# 9  
Old 02-22-2005
Hello again Smilie

I test some awk code, i think i get the idea how to manipulate the date, however, I can't quite get it the way i want
Here is the txt file that i have:

Code:
$ cat test.txt
000702687       Abigail Adams   200
000724961       Andrew  Thompson        400
000710505       Anthony Esteves 20

And the code and output for the code is below:

$  awk '{printf("U%-20s %-0s,%-10s AD100100%-0s00\n", $1, $3, $2, $4)}' test.txt

U000702687            Adams,Abigail    AD10010020000
U000724961            Thompson,Andrew     AD10010040000
U000710505            Esteves,Anthony    AD1001002000

How do i get the colume where "AD...." start to align? the last name doesn't have fix width so it's hard to specify how many character do i need.
Thanks

CT
# 10  
Old 02-22-2005
Code:
awk '{printf("U%-20s %-0s,%-10s %-10s %-0s00\n", $1, $3, $2, "AD100100", $4)}' test.txt

# 11  
Old 02-22-2005
vgersh99,

it still doesn't work Smilie

CT
# 12  
Old 02-22-2005
sorry.
Code:
awk '{_i=$3 "," $2; printf("U%-20s %-20s %-10s %-0s00\n", $1, _i, "AD100100", $4)}' test.txt

# 13  
Old 02-22-2005
vgersh99,

Is there a way i can specify the "lastname, firstname" colume width? let's say 30 for the combination of the name.

Thanks

CT
# 14  
Old 02-22-2005
Quote:
Originally Posted by CamTu
vgersh99,

Is there a way i can specify the "lastname, firstname" colume width? let's say 30 for the combination of the name.

Thanks

CT
nawk -f cam.awk test.txt
default width=20

nawk -v w=30 -f cam.awk test.txt
width=30

nawk -v w=40 -f cam.awk test.txt
width=40

Code:
BEGIN {
  if (w == "")
     w=20
}
{_i=$3 "," $2; printf("U%-20s %-*s %-10s %-0s00\n", $1, w, _i, "AD100100", $4)}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

2. Shell Programming and Scripting

Conversion of below Tabs Tex file into CSV format file : shell script needed

Request if some one could provide me shell script that converts the below "input file" to "CSV format file" given Name Domain Contact Phone Email Location ----------------------- ------------------------------------------------ ------- ----- ---------------------------------... (7 Replies)
Discussion started by: sreenath1037
7 Replies

3. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

4. Shell Programming and Scripting

Finding modified File List after the chosen date in Korne Shell...

I am trying to write a Korne Shell asking the user for a date and a directory and then search recursively in this directory the list of files modified after the date chosen. But I am not getting good results when I Test it... #!/usr/bin/ksh echo "Enter a date (YYYYMMDD) " read date touch -t... (2 Replies)
Discussion started by: marconi
2 Replies

5. Shell Programming and Scripting

Korne Shell...

In Korne Shell Scripting, how to search recursively in a directory, the list of files modified after a given date .. Thanks in advance.. (1 Reply)
Discussion started by: marconi
1 Replies

6. Shell Programming and Scripting

Some Problem with Korne Shell//

I am new to Korne Shell Scripting. Can someone help me with a Korne Shell which asks the user :- 1) to enter the name of a file when searching it recursively (using the find command) in the home directory of this user. 2) for a date (format AAMMJJ) and a directory and then searches ... (4 Replies)
Discussion started by: marconi
4 Replies

7. Shell Programming and Scripting

Korne Shell Problem.

Hi Everyone, I have tried with the following Code for each of the following, but that does not seem to serve the purpose. Can someone give some pointers please. 1) A Korne Shell which asks the user to enter the name of a file when searching it recursively (using the find command) in the... (3 Replies)
Discussion started by: marconi
3 Replies

8. Shell Programming and Scripting

script for format a file

is there any way to format a file by just removing first line and last line from the file. my file is like test.txt 12may2004,20may2004,A 123,SCOTT,TIGER,,,,12,12-MAY-2006 124,TIGER,SCOTT,,,,,,, .... ... 163,cscssaa,abc,,,,12,12-MAY-2006 END my requirement is to produce the same file... (1 Reply)
Discussion started by: u263066
1 Replies

9. Shell Programming and Scripting

GOTO LOOP in KORNE SHELL

All Please help to provide "goto" functionality in KORN shell script. ex: 1: Command Process some command if check some variable true goto 1 else process some other Please help to implement this example in korne... (1 Reply)
Discussion started by: DeepakXavier
1 Replies

10. Shell Programming and Scripting

Mailing in Korne shell

All Iam using Korne shell in AIX OS. Can u give me the syntax to send a mail. Thanx in advance Regards Deepak (5 Replies)
Discussion started by: DeepakXavier
5 Replies
Login or Register to Ask a Question