Results 1 to 5 of 5
Hey guys,
I've been searching and searching and hell I can't find the solution to my problem. Maybe someone here can shed some light on the problem.
Here goes...
Basically, ...
- 10-18-2007 #1Just Joined!
- Join Date
- Oct 2007
- Posts
- 7
Bash Script - Using sed or similar? HELP!
Hey guys,
I've been searching and searching and hell I can't find the solution to my problem. Maybe someone here can shed some light on the problem.
Here goes...
Basically, here is my 'sample code' ...
sn=30
var1=`echo "Johnny" |wc -L`
res=`echo "${sn}-${var1}" |bc`
First line is just a variable definition.
Second line is printing out the length of characters, in this case "6".
Third line is calculating "30-6" to echo me "24". Which it does.
At this point, I want to use (perhaps 'sed'?) to write a file with "Johnny" and 24 white spaces after.
So in my file, I would have: Johnny[24 spaces]
How can I achieve this?
Someone please help me
Thanks!
Scorp.
- 10-18-2007 #2
Well, a few ways you could do this. An easy one is
Code:echo -n "Johnny" > outfile COUNTER=0 while [ $COUNTER -le $res ]; do echo -n ' ' >> outfile let COUNTER+=1 done
- 10-22-2007 #3Just Joined!
- Join Date
- Oct 2007
- Posts
- 7
Doesn't work
Hey,
Is there another way to do this?
For some reason this won't work in my code.
Let me know if there's any other method that I can use.
Thanks!
P.
- 10-23-2007 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
Code:echo "Johnny" | awk '{l=30-length($0);j="%s%"l"s" printf j , l," " > "outfile" }'
- 10-23-2007 #5
...
Code:sn=30 var1="Johnny" printf "%-"$sn"s\n" "$var1">yourfile


Reply With Quote