Append spaces the rows to make it into a required fixed length file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append spaces the rows to make it into a required fixed length file
# 8  
Old 01-03-2013
I need to pass the values as external parameters, i.e., at runtime i want pass the values.
# 9  
Old 01-03-2013
So - assign LENGTH and FILE a runtime, or, replace by e.g. $1 and $2.
# 10  
Old 01-08-2013
The below code do not appened spaces as many as my required length. When i gave length as 285, it append spaces upto 251 only. When i use printf command it shows 285.

But when i write the output to a file, in that the length is only 251 but not 285.

Code:
 
awk -v l="$1" '{s="%-"l"s\n";printf(s,$0);}' input_file


Last edited by Amrutha24; 01-08-2013 at 12:45 AM..
# 11  
Old 01-10-2013
Any proposal above does work on my system, giving lines of 285 chars in total. Do you have limitations on line length or similar?
Post samples of input & output files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make it to fixed length

Hi Team, I have a different length records in my text file.I would like to make all the records with same length. I want to check the maximum lenth and all other records make the same length It's urgent request. Thanks in Advance (2 Replies)
Discussion started by: Anthuvan
2 Replies

2. Shell Programming and Scripting

How to add extra spaces to make all lines the same length?

Hello to all, I'm trying to format a file to have all lines with the same length (the length of the longest line) adding needed extra spaces at the end. Currently I have the awk script below that adds one space the end of each that have a lenght lower than 35, but I don't know how to add... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

3. UNIX for Dummies Questions & Answers

Length of a fixed width file

I have a fixed width file of length 53. when is try to get the lengh of the record of that file i get 2 different answers. awk '{print length;exit}' <File_name> The above code gives me length 50. wc -L <File_name> The above code gives me length 53. Please clarify on... (2 Replies)
Discussion started by: Amrutha24
2 Replies

4. Shell Programming and Scripting

Remove characters from fixed length file

Hello I've question on the requirement I am working on. We are getting a fixed length file with "33" characters long. We are processing that file loading into DB. Now some times we are getting a file with "35" characters long. In this case I have to remove two characters (in 22,23... (14 Replies)
Discussion started by: manasvi24
14 Replies

5. Shell Programming and Scripting

Flat file-make field length equal to header length

Hello Everyone, I am stuck with one issue while working on abstract flat file which i have to use as input and load data to table. Input Data- ------ ------------------------ ---- ----------------- WFI001 Xxxxxx Control Work Item A Number of Records ------ ------------------------... (5 Replies)
Discussion started by: sonali.s.more
5 Replies

6. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

7. UNIX for Dummies Questions & Answers

how to append spaces(say 10 spaces) at the end of each line based on the length of th

Hi, I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is. I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed... (17 Replies)
Discussion started by: prathima
17 Replies

8. UNIX for Dummies Questions & Answers

Convert a tab delimited/variable length file to fixed length file

Hi, all. I need to convert a file tab delimited/variable length file in AIX to a fixed lenght file delimited by spaces. This is the input file: 10200002<tab>US$ COM<tab>16/12/2008<tab>2,3775<tab>2,3783 19300978<tab>EURO<tab>16/12/2008<tab>3,28523<tab>3,28657 And this is the expected... (2 Replies)
Discussion started by: Everton_Silveir
2 Replies

9. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

10. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies
Login or Register to Ask a Question