byte count and cut command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting byte count and cut command
# 1  
Old 04-10-2007
Error 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.

Smilie
# 2  
Old 04-10-2007
1.

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

2.

Use awk.
# 3  
Old 04-10-2007
ksh/bash
1.
Code:
$ a=abc@yahoo.com 
$ echo ${#a}
13

Code:
$ echo "abc.|de" | awk -F'.|' '{ print $1}'
abc

(note not all awks will allow this, on solaris use nawk)
# 4  
Old 04-10-2007
1)
Code:
# printf "abc@yahoo.com" |wc -c
13

2) another way,
Code:
# var=abc@#yahoo.com
# IFS="@#"
# echo $var
abc  yahoo.com
# set - $var
# echo $1
abc
# echo $3
yahoo.com

# 5  
Old 04-12-2007
Thank you all of you.

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

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

2. Shell Programming and Scripting

How To Count Fields For Cut?

I am new to cut and I want to use the field option with a space delimiter on an Apache log file. For example, if I wanted to find the 200 HTTP code using cut in this manner on the file below cat access_abc.log | cut -d' ' -f7 | grep "200" 157.55.39.183 - - "GET /content/696-news041305... (4 Replies)
Discussion started by: sharingsunshine
4 Replies

3. UNIX for Advanced & Expert Users

Issue with rm command in a tera byte file system

We have a production file system which has 6+ million files with more than 1 tera byte in size. When trying to delete selective files through a weekly script files are not deleted. Please advise with ideas. (5 Replies)
Discussion started by: kppublicmail
5 Replies

4. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

5. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

6. Shell Programming and Scripting

Remove a byte(Last byte from the last line)

Hi All Can anyone please suggest me how to remove the last byte from a falt file .This is from the last line's last BYTE. Please suggest me something. Thank's and regards Vinay (1 Reply)
Discussion started by: vinayrao
1 Replies

7. Shell Programming and Scripting

Check if 2 files are identical byte-to-byte?

In my server migration requirement, I need to compare if one file on old server is exactly the same as the corresponding file on the new server. For diff and comm, the inputs need to be sorted. But I do not want to disturb the content of the file and need to find byte-to-byte match. Please... (4 Replies)
Discussion started by: krishmaths
4 Replies

8. UNIX for Dummies Questions & Answers

row count of all files with more than 0 byte

Hi, Is there any way to get count number of lines in all files which have more than o bytes in current directory for example : in /user/sri/ there are 3 files abc 0 bytes def 5 bytes ghi 10 bytes i need to get wc -l for all files which have > 0 bytes at a time ..is... (6 Replies)
Discussion started by: sri2005
6 Replies

9. Shell Programming and Scripting

no count of spaces in cut

i want to give numbers to cut without worrying about the spaces; echo "12 345 6 78 9" | cut -c 1-9 echo "123 456 789" | cut -c 1-9 echo "1 2 3 4 5 6 7 8 9" | cut -c 1-9 the output of these three must be allways; 123456789 is that posible? (6 Replies)
Discussion started by: Tártaro
6 Replies

10. Shell Programming and Scripting

Cut output to same byte position

Hi folks I have a file with thousands of lines with fixed length fields: sample (assume x is a blank space) 111333xx444TTTLKOPxxxxxxxxx I need to make a copy of this file but with only some of the field positions, for example I'd like to copy the sample to the follwing: so I'd like to... (13 Replies)
Discussion started by: HealthyGuy
13 Replies
Login or Register to Ask a Question