Please support our Shell Scripting advertiser: Programming Forums
Views: 12664 | Replies: 27
![]() |
•
•
Join Date: Jul 2005
Posts: 23
Reputation:
Rep Power: 4
Solved Threads: 0
I have a script that I'm working on to pad files with spaces. The spaces need will vary. This is what I have so far but it isn't working. Any suggestions?
#!/bin/bash
echo -n "Enter filename "
read filename
echo -n "Enter start size "
read start
echo -n "Enter stop size "
read stop
while [ $start < $stop ]; do
sed '/$/G' >>$filename
done
wc -m $filename
#!/bin/bash
echo -n "Enter filename "
read filename
echo -n "Enter start size "
read start
echo -n "Enter stop size "
read stop
while [ $start < $stop ]; do
sed '/$/G' >>$filename
done
wc -m $filename
•
•
Join Date: May 2005
Posts: 215
Reputation:
Rep Power: 4
Solved Threads: 0
I am not totally following what the whole script is supposed to be doing. By padding, do you mean addings spaces, if so, what are you adding the spaces to? I have only used sed alittle bit, but I am not following what you are trying to accomplish with the sed command. I would like to help just need a little more info :-)
•
•
Join Date: Jul 2005
Posts: 23
Reputation:
Rep Power: 4
Solved Threads: 0
Well, I need to add blank spaces at the end of a UNIX/Linux file so that the user can specify what length it needs to be and it will be filled in the rest of the way with spaces so it will satisfy the required characters. When the user asked me about this it sounded a lot more complicated than it now seems. I believe all I need to do is have him put an awk/sed command (whichever can do this) with the number of spaces he needs and let it run from a command line instead of creating a script. I hope this helps. The request was vague and now I'm going on three days trying to punch through this.
•
•
Join Date: May 2005
Posts: 215
Reputation:
Rep Power: 4
Solved Threads: 0
Something like this should work for you
this will add the amount of space you need. Are you looking to have the script do more?
edit added later//
I just reread your post, now I see what you are trying to do, I will see if I can do it differently.
echo "enter the file name you want to pad"
read file
echo "enter the amount of spaces you want to add"
read add
x=0
while [ $x != $add ]
do
x=`echo "$x + 1" | bc`
echo "" >> file
doneedit added later//
I just reread your post, now I see what you are trying to do, I will see if I can do it differently.
•
•
Join Date: May 2005
Posts: 215
Reputation:
Rep Power: 4
Solved Threads: 0
this should work, it seems messy, but seems to do the job
#!/bin/bash
echo "enter the name of the file you want to pad"
read file
echo "enter the total amount of characters you need in the file"
read total
while [ "`wc -m $file`" != "`echo "$total $file"`" ]
do echo "" >> $file
done•
•
Join Date: May 2005
Posts: 215
Reputation:
Rep Power: 4
Solved Threads: 0
•
•
•
•
Originally Posted by gritty
the last one does pad, but it doesn't stop. I'm going to see why. Thanks for all your help
you give the script the variable, which is the file you want to pad
then you tell it how many characters you need in the file, then it fills the file with spaces until it reaches the amount you told it to pad to. Then it stops.
How do you want it to work differently, just curious(having fun)?
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode