Append strings with filler spaces


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Append strings with filler spaces
# 1  
Old 08-11-2005
Append strings with filler spaces

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 several spaces as follows

1 2 3 4 etc.

When i echo $inrec to screen i see the output as

1 2 3 4 (i.e each bunch of spaces is being treated as one)

This is fine for what i wanted to do.
But now i want to append a number (say 99) onto the end of each $inrec when sending it to the TMP file. So i tried this

echo $inrec$num

But the output shows this
992 3 4

WHen i put speech marks around the variables the output showed

1 2 3 499

but i only need one space as before.

Any ideas.
# 2  
Old 08-11-2005
As I understand you need all the numbers delimited by a space

Did you try this ?

echo "$inrec"" """$num" >> TMP

vino
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to append strings with whitespace?

Hi, Need help. This seems simple but I tried many things but failed to get what I wanted. Below is the input file: ... (7 Replies)
Discussion started by: bunny_merah19
7 Replies

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

3. Shell Programming and Scripting

Need to append matching strings in a file

Hi , I am writing a shell script to check pvsizes in linux box. # for i in `cat vgs1` > do > echo "########### $i ###########" > pvs|grep -i $i|awk '{print $2,$1,$5}'>pvs_$i > pvs|grep -i $i|awk '{print $1}'|while read a > do > fdisk -l $a|head -2|tail -1|awk '{print $2,$3}'>pvs_$i1 >... (3 Replies)
Discussion started by: nanduri
3 Replies

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

5. Shell Programming and Scripting

Treating Strings with spaces

I have a file list.txt which has a list of file names with spaces between the file names like /emptydir/file 1 how do i browse through the list.txt displaying the filenames. Almost all the file names in list.txt have space between them.This file list.txt is formed by using the find statement to... (5 Replies)
Discussion started by: kinny
5 Replies

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

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

9. Shell Programming and Scripting

Need help with command to append strings

Greetings all, I'm in need of some help in coming up with this command which requires me to append 5 strings together: 1. echo "Status from system:" 2. `cat logs.txt` (i need the output of this command) 3. echo "Error output: " 4. `cat errors.txt`(i need the output of this command) 5.... (3 Replies)
Discussion started by: rockysfr
3 Replies

10. UNIX for Dummies Questions & Answers

How to append "spaces" between strings

HI, Supose I have the folowing strings: "unix" and "linux". I want to concatenate the two strings, inserting between them a variable number of spaces. ex1: unix linux ex2: unix linux Can you help me in this simple problem? Regards, Elio (2 Replies)
Discussion started by: efernandes
2 Replies
Login or Register to Ask a Question