Hi kenisand ,
Actually my problem is that i have column in a fixed length file that is right alingned. I need to change that column to make it right aligned.
The problem is that the length of the column is 5, and it can hold a max of 5 characters. So i do not know the number of spaces that are preceding a valid character.
For Eg : Records in the file are as follows :
Cl1 Cl2 Cl3
Rec 1 :ABC 3DEF
Rec 2 :EFG 34HIJ
In the above file, has 3 cols
first record is : Col1 "ABC", Col2:" 3" and col3:"DEF"
second record :Col1 "EFG", Col2:" 34" and col3:"HIJ"
Now my requirement is to change the right alignement of the 2 nd col in the file to left alignement.
I want the output to be as follows :
Cl1 Cl2 Cl3
Rec 1 :ABC3 DEF
Rec 2 :EFG34 HIJ
If i can find the number of spaces preceding the valid character then i can use the solution u hav suggested, but this count can be variable and that is the problem.
$
$ x=" 12"
$ xspace=${x%%+([! ])}
$ typeset -R6 rightx=$x
$ typeset -L6 leftx=$x
$ echo number of leading blanks is ${#xspace}
number of leading blanks is 5
$ echo "rightx=<${rightx}> leftx=<${leftx}>"
rightx=< 12> leftx=<12 >
$
You should read "man ksh", it's all in there...but briefly: ${var%%pattern} removes the largest string that matches the pattern from the end of the value of the variable. And +([! ]) is a pattern that matches non-blanks.