byte count and cut command

  1. Is there a way to count the number of bytes of a variable?
    example:
    abc@yahoo.com is 13 bytes

  2. Cut command only allows one byte for delimiter
    example: cut -f1 -d'.'
    delimited by period. Is there a way to have two or more characters in the delimiter field?

thanks in adavance.

:slight_smile:

var=abc@yahoo.com
echo ${#var}

Use awk.

ksh/bash
1.

$ a=abc@yahoo.com 
$ echo ${#a}
13
$ echo "abc.|de" | awk -F'.|' '{ print $1}'
abc

(note not all awks will allow this, on solaris use nawk)

1)

# printf "abc@yahoo.com" |wc -c
13

2) another way,

# var=abc@#yahoo.com
# IFS="@#"
# echo $var
abc  yahoo.com
# set - $var
# echo $1
abc
# echo $3
yahoo.com

Thank you all of you.

All the suggestions seems to work. New things to learn.

:slight_smile: