Please support our Shell Scripting advertiser: Programming Forums
Views: 12639 | Replies: 27
![]() |
•
•
Join Date: May 2005
Posts: 215
Reputation:
Rep Power: 4
Solved Threads: 0
you could also check to see what is happening in the file with an some echo statments
#!/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
# this echo statmernt may show you what is happening
echo `wc -m $file`
# thes next two lines of code will put a pause inbetween each loop so you are able to read it as it happens
echo "enter return to continue"
read X
done•
•
Join Date: May 2005
Posts: 215
Reputation:
Rep Power: 4
Solved Threads: 0
•
•
•
•
Originally Posted by gritty
I'm getting a too many arguments error:
bash-2.05$ testscript2
enter the file name you want to pad
testfile
enter the amount of characters you would like in the file
90
./testscript2: [: too many arguments
bash-2.05$
hmm. it works on mine. I am guessing you are not able to cut and paste. Maybe you have a typo.
•
•
Join Date: May 2005
Posts: 215
Reputation:
Rep Power: 4
Solved Threads: 0
I have an idea. Maybe on solaris the output of wc -m is different. on linux the output of
is
this is assumbing there is 23 characters.
what does the output of wc -m look like with solaris?l
wc -m file_name
is
23 file_name
what does the output of wc -m look like with solaris?l
•
•
Join Date: May 2005
Posts: 215
Reputation:
Rep Power: 4
Solved Threads: 0
I was thinking about that script, using the tr command to splice off the letters will fail on any file name that contain numbers. The following command will fail becaise it will also remove numbers from your charcater count
the problem is if the file name has a number in it and the amount of characters in that file has that number also, it will remove the number.
lets say the output of the command
you will get
now tr will remove all of the following characters "test_file2.avi" so your trimmed output will be missing a 2 like this
you could solve this problem by using sed(I know it was not working for you). Using the substitiuion parameter of sed would allow you to find the whole string and substitute it with nothing, in effect deleting it.
wc -m $FILE | tr -d $FILE
the problem is if the file name has a number in it and the amount of characters in that file has that number also, it will remove the number.
lets say the output of the command
wc -m test_file2.avi
2445 test_file2.avi
you could solve this problem by using sed(I know it was not working for you). Using the substitiuion parameter of sed would allow you to find the whole string and substitute it with nothing, in effect deleting it.
echo "enter the file name you want to pad"
read FILE
echo "enter the amount of characters you would like in the file"
read TOTAL
while [ `wc -m $FILE | sed "s/$FILE//"` -lt $TOTAL ]
do echo "" >> $FILE
done•
•
Join Date: Jul 2005
Posts: 23
Reputation:
Rep Power: 4
Solved Threads: 0
Great thanks, your right. Plus I had to tweak it some more because I was told sometimes the file has too many spaces at the end so the script had to add OR subtract spaces. This wasn't too bad though, I just added a sed command and mv after the file name was read:
sed -e '/^$/ d' $FILE>temp_padding_file
mv temp_padding_file $FILE
and that stripped the spaces off end before even starting to loop. Thanks again for your help.
sed -e '/^$/ d' $FILE>temp_padding_file
mv temp_padding_file $FILE
and that stripped the spaces off end before even starting to loop. Thanks again for your help.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode