I want to count the number of starting space at the beginning of line. My sample text file is following
aaaa bbbb cccc dddd
aaaa bbbb cccc dddd
aaaa bbbb cccc dddd
aaaa bbbb cccc dddd
Now when I write a simple script to count, I notice the different between inline command and full script of awk ouput.
First try
#!/bin/bash
while IFS= read -r line; do
echo "$line" | awk '
{
FS="[^ ]"
print length($1)
}
'
done < "tmp"
The output is
4
4
4
4
Second try
#!/bin/bash
while IFS= read -r line; do
echo "$line" | awk -F "[^ ]" '{print length($1)}'
done < "tmp"
The output is
0
2
4
0
I want to write a full script which has inline type output.
Could anyone explain me about this different? Thank you very much.
awk 'BEGIN { FS="[^ ]" } { print length($1) }'in your first one.