I am looking for the way to add variable number of spaces between two string. e.g input line is
a ,bb
abc ,bcb
pqr ,bfg
My output should be something like this
a ,bb
abc ,bcb
pqr ,bfg
This text are basically inside a file. So I tried like this
while read line
do
IFS=','
set $line
printf '%s' "$1" >> out.txt
## Here I have to include space to arrange line properly
printf '%s,' "$pading" >> out.txt
printf '%s\n' "$2" >> out.txt
done < $fname
Thanks
---------- Post updated at 04:18 AM ---------- Previous update was at 04:13 AM ----------
Well I am not able to show the require output properly . The only thing which I want is second column should be start at same point.Like
bg
bc
Yes, offcourse we can have different seprators in code, also I have changed my solution a bit in previous posts in which I am reading file 2 times. Following is an example for separator ; .
Input_file:
cat check_space
a ;bb
abc ;bcb
pqr ab ;bfg
Output will be as follows.
awk -F";" 'FNR==NR{l=length($1) > l?length($1):l;next} {$1=sprintf("%-"l"s",$1)} 1' OFS=";" Input_file Input_file
a ;bb
abc ;bcb
pqr ab ;bfg
Thanks,
R. Singh
---------- Post updated at 07:29 AM ---------- Previous update was at 06:56 AM ----------
Hi derekludwig,
I have fixed the same and mentioned in POST#10. Also you can't hardcode value of "%-20s as it is dependent on 1st field.
so we can better take length of first field and do the operation accordingly.