append space to a varaible using sed


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers append space to a varaible using sed
# 1  
Old 10-24-2007
append space to a varaible using sed

Hi,

I would like to append 100 blank spaces to a variable using sed.
eg:
var1=abcdef

Could anyone advice???

thanks,
Sumith
# 2  
Old 10-24-2007
Try this:
Code:
var1=abcdef
i=0
while [ $i -lt 100 ]
do
var1="${var1} "
i=`expr $i + 1`
done

After running this loop, if I type echo $var1 or even echo =${var1}= I don't see hundred spaces, but I see them in the value of var1 using set command.
# 3  
Old 10-25-2007
First off: honestly, this sounds like homework, because a practical reason why anyone woukd want to do this is not conceivable for my simple brain.

Anyways, giving you the benefit of doubt, here is how it goes, the text between "<" and ">" is to be replaced of course:

Code:
var1="abcd"

print - "\"${var1}\""

var1="$(print - "var1" | sed 's/.*/&<....insert 100 spaces here...>/')"

print - "\"${var1}\""

the two "print - ..." - statements are just there to show you the content before and after (surrounded by double quotes).

bakunin
# 4  
Old 10-25-2007
This does indeed sound like homework. Not only for the strange requirement (I too cannot think of a valid reason for doing this), but the fact that you've specified which command needs to be used to fulfil the requirement.

Hence, I'm locking this thread.

Thanks,
ZB
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Passing a varaible to sed issue

I am unable to make it work. I tried dbl quotes ...etc. Nothing works. I am trying to replace value in an XML file to current system date/time. Here is my code: NTIMESTAMP=`date '+%m%d%Y%H%M%S'` sed -e 's|<TIMESTAMP>\{1,\}|<TIMESTAMP>$NTIMESTAMP|g' $QLOG Input data sample: ... (5 Replies)
Discussion started by: mrn6430
5 Replies

2. UNIX for Dummies Questions & Answers

To flat file, append null or space if its length is less than 10

Hi, We receive flat files with fixed width data Now our goal is append from right null or space to each record if the lenght of the record is less than for example 10. for example 123 45 6 0 123 45 123 45 6 123 and output should be 123 45 6 0 123 45**** 123 45 6**... (7 Replies)
Discussion started by: shharrath
7 Replies

3. Shell Programming and Scripting

Append variable value with sed

I have a requirement where I need to add a variable value based on a pattern match. When I try this it works: sed '/IS_ETL_DEV/a\ ABCD' File1.txt > File1.tmp Now I want to replace IS _ETL_DEV with a variable like $Pattern and replace the values ABCD with a variable $Var the value "$$XYZ=1".... (4 Replies)
Discussion started by: vskr72
4 Replies

4. Shell Programming and Scripting

sed append without using new line

im trying to append to the end of the line using sed but I want to do it without creating a new line the text to which I want to append is all in capital letters. I want to do something like this: LINE]Foo but when I do this: //a\ ] Foo it prints foo on a new line: LINE ]Foo ... (11 Replies)
Discussion started by: mrjavoman
11 Replies

5. Shell Programming and Scripting

sed append to string

I am trying to replace in multiple files every instance of text that begins with http and add hyperlink characters to it. I can get it to work with the following:sed -e "s/http*.*/<a href=\"&\">&<\/a>/g" * as long as the http text is at the end of the file. I need it to stop at the end of the... (2 Replies)
Discussion started by: numele
2 Replies

6. Shell Programming and Scripting

sed append words

Hi all, I have a file like one two three for five six seven eight ..... Actually i need to append a label to the words that belong to the 2 column and get: one two_label three for five six_label seven eight .... I was trying with sed inside vim but I can't figure out... (9 Replies)
Discussion started by: Dedalus
9 Replies

7. Shell Programming and Scripting

sed append in first column

hi, anyone can give a sample command on sed. the text file date list belows; test.txt "a","bbb",123 "b","ccc",234 "c","eee",456 output i need to add these word "xxx" "xxx","a","bbb",123 "xxx","b","ccc",234 "xxx" ,"c","eee",456 thanks in advance, FSP (4 Replies)
Discussion started by: fspalero
4 Replies

8. Shell Programming and Scripting

How to append using sed

Hello all, I want to use sed to append a variable stored in $i, how do i do that? $i contains a path to a directory and i want to append it before the result i get from awk statement, before affecting awk results. rite now out put i get from code below is:- The path is:... (2 Replies)
Discussion started by: asirohi
2 Replies

9. Shell Programming and Scripting

append blank space

Hi, I would like to add blank space for fixed length(50) if length of string <30. Scenario: File Size AAA.CSV 123 BB.CSV 134 Expected: File Size AAA.CSV 123 BB.CSV 134 I want append blank space until 30 character. Thanks and Regards, HAA (1 Reply)
Discussion started by: HAA
1 Replies

10. Shell Programming and Scripting

append to fle using sed

Hello , I have the folloiwing command : sed -n "$var,$final w $destfile" $sourcefile where : $var - $final represent the range of line numbers to be written in $destfile However I require this command to work in a loop for which i need the sed command to keep appending the output to the... (2 Replies)
Discussion started by: shweta_d
2 Replies
Login or Register to Ask a Question