RSS Forums RSS
Please support our Shell Scripting advertiser: Programming Forums
Views: 12639 | Replies: 27
Reply
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: help with shell script padding files with spaces

  #21  
Jul 21st, 2005
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
Reply With Quote  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: help with shell script padding files with spaces

  #22  
Jul 21st, 2005
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.
Reply With Quote  
Join Date: Jul 2005
Posts: 23
Reputation: gritty is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
gritty gritty is offline Offline
Newbie Poster

Re: help with shell script padding files with spaces

  #23  
Jul 21st, 2005
I'm still getting a too many arguments error. I can try this script at home on Linux. Maybe it's not working because it's on Solaris 9 right now.
Reply With Quote  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: help with shell script padding files with spaces

  #24  
Jul 21st, 2005
I have an idea. Maybe on solaris the output of wc -m is different. on linux the output of
wc -m file_name

is
23 file_name
this is assumbing there is 23 characters.

what does the output of wc -m look like with solaris?l
Reply With Quote  
Join Date: Jul 2005
Posts: 23
Reputation: gritty is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
gritty gritty is offline Offline
Newbie Poster

Re: help with shell script padding files with spaces

  #25  
Jul 21st, 2005
it is the same. I thought that there was a command line in awk or sed that gives you the ability to add a specified amout of spaces to a file and send it to the stdout. I just can't find it.
Reply With Quote  
Join Date: Jul 2005
Posts: 23
Reputation: gritty is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
gritty gritty is offline Offline
Newbie Poster

Re: help with shell script padding files with spaces

  #26  
Jul 21st, 2005
DUDE!!! It works!!! I had to just add -d to the tr and then WHAM!
Thanks sooo much for all your help. I owe ya one.
Reply With Quote  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: help with shell script padding files with spaces

  #27  
Jul 24th, 2005
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
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
you will get
2445 test_file2.avi
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.

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
Reply With Quote  
Join Date: Jul 2005
Posts: 23
Reputation: gritty is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
gritty gritty is offline Offline
Newbie Poster

Re: help with shell script padding files with spaces

  #28  
Jul 25th, 2005
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:47 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC