append blank spaces at the end of a variable string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting append blank spaces at the end of a variable string
# 1  
Old 06-17-2012
append blank spaces at the end of a variable string

Hello, could you please help with this one. I have an input file like this:
Code:
123,4567,89000
123456789,9876543,12

and for the output I need strings to be with the fixed length, let's say 15, and if the string is -lt 15 to be populated with blanks at the end until it reach 15, like this:
Code:
123 ,4567 ,89000 
123456789 ,9876543 ,12

I tried this, but it is not working....
Code:
while [ $len -lt 15 ]; do $1=`echo " "$1`; done

Thanks!

Last edited by Scrutinizer; 06-17-2012 at 09:31 AM.. Reason: code tags also for data
# 2  
Old 06-17-2012
Try this
Code:
awk -F',' '{OFS=","}{ for (i=1;i<NF;i++) {printf("%-15s,",$i)}{printf($NF"\n")}}' file1

This User Gave Thanks to jawsnnn For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Append Spaces to a string

Hi, I am new to Unix. I need help in writing a code and the requirements are of as below: 1) The code is in awk code 2) Append multiple spaces to a string Example: Address = "House_NO:1100" I have to make sure the length of Address should be always 100, if it is less than 100, i have to... (5 Replies)
Discussion started by: Venu Gopal
5 Replies

2. AIX

How to append spaces to string values?

i/o file: abc,efg,xyz Required o/p file: "abc (Value + blank spaces=16) " ,"efg (Value +blank spaces=15) " ,"xyz (Value+ blank spaces =20) " In short input file value stores in result file with " i/p Value " added with spaces and are of fixed size like 16,15,20 How to do using... (2 Replies)
Discussion started by: AhmedLakadkutta
2 Replies

3. Shell Programming and Scripting

how to add blank spaces at the end of every record in a file.

hi, Does anyone has any idea in adding few blank spaces at the end of every record in a file. Eg: file.txt Baby Boy Kim 1234 Baby Boy Vik 1334 Desired output:- output.txt Baby Boy Kim 1234 Baby Boy Vik 1334 I want to add 10 blank spaces at the end every record in file.txt (3 Replies)
Discussion started by: techmoris
3 Replies

4. Shell Programming and Scripting

append end of line with 8 spaces

child_amt=$amount prev_line="$prev_line $child_amt" i am getting the result like this 21234567890001343 000001004OLFXXX029100020091112 0000060 but i want 8 spaces between the eg: 21234567890001343 000001004OLFXXX029100020091112 0000060 how can i do this in .ksh (1 Reply)
Discussion started by: kshuser
1 Replies

5. UNIX for Dummies Questions & Answers

selective removal of blank spaces in string

Hi, I'm a newbie to shell scripting and I have the following problem: I need all spaces between two letters or a letter and a number exchanged for an underscore, but all spaces between a letter and other characters need to remain. Searching forums didn't help... One example for clarity: ... (3 Replies)
Discussion started by: Cpt_Cell
3 Replies

6. 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

7. Shell Programming and Scripting

append string with spaces to a line

hi i have a file like (every string contains 16 chars) CTL1330000000000 0000 00 008000 0080000000 i need to form a line and write to a file CTL13300000000000000 00008000 0080000000 total chars should be 64 ... (2 Replies)
Discussion started by: Satyak
2 Replies

8. Shell Programming and Scripting

Append Spaces At end of each line Leaving Header and Footer

How to append constant No of spaces suppose 52 at end of each line in a file (xyz) excluding first and last line. Please Help me out for the same. (1 Reply)
Discussion started by: deepam
1 Replies

9. UNIX for Dummies Questions & Answers

string with blank spaces

I have a file that has dates like this: date FINAL_RESULT; 7 date FINAL_RESULT; 2 date FINAL_RESULT; 5 With this command: seira=`cut -f2 -d\; tes.txt` i take the date FINAL RESULTs and i store them on variable seira.then seira look like this: 6 3 8 I want to read seira and make a sum of all... (4 Replies)
Discussion started by: psalas
4 Replies

10. Shell Programming and Scripting

remove blank spaces in a string

can any help how to remove blank spaces in a string? STR="GOOD BYE" by removing blank spaces, the string should be GOOD,BYE thanks in advance (2 Replies)
Discussion started by: spandu
2 Replies
Login or Register to Ask a Question