Please suggest how to maintain the spaces.
Use a field separator:
$ echo "First Names City Names ES"|awk -F'[ ]' '{$1=$2=$NF="";print $0}'
City Names
I have one more doubt about wc -c output , it always gives 1+ to actual value
That's because of the newline. Instead of echo
, you can say echo -n
so as to disable the trailing newline.
$ echo | wc -c
1
$ echo -n | wc -c
0