Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Append Spaces to a string


 
Thread Tools Search this Thread
# 1  
Linux 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 add remaining with spaces, so that length(Address) =100 always

Address = Address + (Spaces)

Thanks in Advance,
Venu Gopal K
# 3  
Akshay,

Please respect if someone in the forum is asking OP a question. Please do refrain from posting answers before the OP get back to us with an answer to the question raised.

I am requesting so just to make sure that the special homework rules are followed.

Thank you
# 4  
Moderator's Comments:
Mod Comment Akshay Hegde's post has been hidden until we determine whether or not this thread is a misposted homework item.

Venu Gopal: If this is a homework item, let us know quickly so we can close this thread and you can resubmit the question in the proper forum with the filled out homework template. If this is not a homework item, please explain to us what you are working on that requires padding a field to 100 characters.

Akshay Hegde: Our continued support by class instructors depends on us recognizing homework items and on us to help students learn how to do their own homework. The UNIX and Linux Forums can't be thought of as a way for students to get someone else (us) to do their homework for them.
# 5  
I am Sorry Yoda and Don Cragun, I started answering this thread as soon as I found in Quick Links today's post, and there were no reply to this post, so I answered, and there after I went for Christmas Celebrations. But unfortunately your reply appeared first before my reply, if I would have seen your reply first in this thread regarding whether its homework question or not, I would not been answered to this thread. My apologies please.

Thanks,

Akshay Hegde
# 6  
Thanks for you replies and advice. This is not a homework assignment. This is a part of my code development. Currently i am using as below. Please let me know whether this is right way or is there any other simple way to pad the spaces.

Code:
while (a++<(40-length(Address))) s=s " ";
Address=Address""s

Thanks.

---------- Post updated at 12:05 PM ---------- Previous update was at 11:53 AM ----------

I will raise my question under proper category by following post rules. Please close this thread.

Thanks

Last edited by Don Cragun; 12-25-2013 at 03:00 PM.. Reason: Add CODE tags
 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
append blank spaces at the end of a variable string
apenkov
Hello, could you please help with this one. I have an input file like this: 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: 123 ,4567...... Shell Programming and Scripting
1
Shell Programming and Scripting
How to append spaces to string values?
AhmedLakadkutta
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...... AIX
2
AIX
how to append spaces(say 10 spaces) at the end of each line based on the length of th
prathima
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...... UNIX for Dummies Questions & Answers
17
UNIX for Dummies Questions & Answers
append string with spaces to a line
Satyak
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 ...... Shell Programming and Scripting
2
Shell Programming and Scripting
Append strings with filler spaces
handak9
Hi I am looping through the contents of a file as follows cat file |while read inrec do echo $inrec >> $TMP done (obviously this isn't all i am doing as it would be pointless but for the sake of the problem this is the important bit) The file has fields which are separated by...... UNIX for Dummies Questions & Answers
1
UNIX for Dummies Questions & Answers

Featured Tech Videos