Filling in characters to line a file up


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filling in characters to line a file up
# 1  
Old 07-26-2004
Filling in characters to line a file up

Hi there, Ive got a feeling this is quite complex but I have a Comma delimited file which is being transfered up to a mainframe and I have to get every column lining up , I need to add in characters to line it up (but different characters and in different positions based on what field/column it is.

For example here is my original file ......


12345,abcdef,123456789,abcd
123456,abcdef,1234567,abcd

and here is what i need doing ............

1) IF data in field 1 is less than 6 characters long then put enough spaces after the last character to make it up to 6

2) Fields 2 and 4 are fixed at 7 characters and will always be populated by 7 character data

3) IF data in Field 3 is less than 10 characters then place leading zero's in front until 10 characters long

So the end result will look like this...

12345 ,abcdef,0123456789,abcd
123456,abcdef,0001234567,abcd

all lined up lovely for processing

If anybody could give me a few tips on what i would need to do to get started on this and what programs i need to use etc then that would be fantastic

cheers
Gary
# 2  
Old 07-27-2004
Example in ksh -
Code:
#!/bin/ksh
IFS=","
export IFS
while read -r one two three four;
   do
       printf "%6d,%s,%10d,%s\n" "$one" $two"  "$three" "$four"
done <  /path/to/your/inputfile

This will output to the screen and will add your spaces to the begining of the field but it's just an example. I leave it to you to change the printf statement. Check the man page for printf and formats. Or, just send it to those mainframe jockeys and let them do it Smilie - or wait for one of the resident awk/sed experts here to give you a one-liner!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying characters on each line in a file

Hello, I would like to copy the first and third char on each line of a file and place them in the 14h and 17th char positions. The file name is listed first and is 6 char's and the dir name is second and also same char size on each line. The file has thousands of lines. Initial... (6 Replies)
Discussion started by: dmm
6 Replies

2. Shell Programming and Scripting

Find new line characters in a file

Hi All, I need to find new line characters in a file and their location in the file and print the results. can someone pleas help. KM (4 Replies)
Discussion started by: Kevin Tivoli
4 Replies

3. Shell Programming and Scripting

Script filling password from command line

I have this command that i am calling from php (exec()): openssl pkcs12 -export -in cert.pem -inkey key.pem -out cred.p12 and then i need to insert password twice Enter Export Password: Verifying - Enter Export Password: I need script that will fill the password... (3 Replies)
Discussion started by: rockyada
3 Replies

4. Shell Programming and Scripting

cut certain characters for each line in a file

Hi Everyone, i have a file 1.txt <a><a"" dd>aaaaauweopriuew</f><">!(^)!</aa></ff> <a><a"" dd>bbbbbuweopriuew</f><">!(^*)!</aa></ff> i know i can use perl -p -i -e "s/>aaaaa/aa/g" 1.txt perl -p -i -e "s/>bbbbb/bb/g" 1.txt to acheive only keep the first two characters of the five characters,... (4 Replies)
Discussion started by: jimmy_y
4 Replies

5. Shell Programming and Scripting

New line characters in Ascii file

I am having a file(1234.txt) downloaded from windows server (in Ascii format).However when i ftp this file to Unix server and try to work with it..i am unable to do anything.When i try to open the file using vi editor the file opens in the following format ... @ @ @ @ @ @ @ @... (4 Replies)
Discussion started by: appu2176
4 Replies

6. Shell Programming and Scripting

Delete new line characters from a file

Hi, I have a file with about 25 colums separated with '~', but few of the lines have extra tabs ('^') and new line characters ('$'). Is there a way I can delete those characters if they are anywhere before the 25th column in a line? example: CLUB000650;12345678;0087788667;NOOP MEMBER ... (4 Replies)
Discussion started by: rudoraj
4 Replies

7. UNIX for Dummies Questions & Answers

First Three Characters of the first line of a file

Dear Members, For example i have a file which contains 10 lines as below: 123testing gopjp jg9459\ 834789rh fh456 47rf 497rvg 409748\ 08ntr i need the first three characters of the first line of the file. if i use cut -c 1-3 < sample.txtits displaying the 1st three... (8 Replies)
Discussion started by: sandeep_1105
8 Replies

8. Shell Programming and Scripting

how to cut first 3 characters of each line in a file

Hi Friends I have a file like sample1.txt ------------ 10998909.txt 10898990.txt 1898772222.txt 8980000000000.txt I need to take first 3 characters of each line in a file and i need to print it ' like loop 109 108 189 898 (7 Replies)
Discussion started by: kittusri9
7 Replies

9. Shell Programming and Scripting

how to count characters by line of file ?

Hello, Member or professional need help how to count characters by line of file Example of the file is here cdr20080817164322811681txt cdr20080817164322811txt cdr20080817164322811683txt cdr20080817164322811684txt I want to count the characters by line of file . The output that I... (4 Replies)
Discussion started by: ooilinlove
4 Replies

10. Shell Programming and Scripting

How to replace characters 7 through 14 of every line in a file

Hi all, I have a file with multiple lines. I want to replace characters 7 through 14 of every line with 0000000 Input: 12345678901234567890 23456789012345678901 Output 12345600000004567890 23456700000005678901 Please help. JaK (9 Replies)
Discussion started by: jakSun8
9 Replies
Login or Register to Ask a Question