How to count the string length


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to count the string length
# 1  
Old 06-15-2006
How to count the string length

Please can anyone tell me, how to count the string length
This User Gave Thanks to Anshu For This Post:
# 2  
Old 06-15-2006
One way is to assign it to a variable. And then do ${#variable}. The other would be to traverse through the string and keep a count.
# 3  
Old 06-15-2006
Another is using "wc" though I think it also couts "return char"...
For instance, in AIX with bash:
echo helo | wc -m
returns 5
echo -e "helo\c" | wc -m
returns 4
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to count the length of fasta sequences?

I could calculate the length of entire fasta sequences by following command, awk '/^>/{if (l!="") print l; print; l=0; next}{l+=length($0)}END{print l}' unique.fasta But, I need to calculate the length of a particular fasta sequence specified/listed in another txt file. The results to to be... (14 Replies)
Discussion started by: dineshkumarsrk
14 Replies

2. Shell Programming and Scripting

Grep a string and count following lines starting with another string

I have a large dataset with following structure; C 0001 Carbon D SAR001 methane D SAR002 ethane D SAR003 propane D SAR004 butane D SAR005 pentane C 0002 Hydrogen C 0003 Nitrogen C 0004 Oxygen D SAR011 ozone D SAR012 super oxide C 0005 Sulphur D SAR013... (3 Replies)
Discussion started by: Syeda Sumayya
3 Replies

3. UNIX for Dummies Questions & Answers

Count on grep for more than two values in a row of fixed length file

I want to get count on number of records in a few folders by running grep command for more than two columns in a row of fixed length file. suppose if i have a fixed length file has 5 columns and I want to see the record counts for country =can and province = bc and time stamp <= 12 feb 2013... (14 Replies)
Discussion started by: princetd001
14 Replies

4. Shell Programming and Scripting

awk length count

Morning, every one. I have a file like this: AAEQGAGNQPQH 27 AAGETQY 51 AAGGSSYNEQF 12 AAGGYEQY 72 AAGLEAKNIQY 159 AAGPYEQY 26 AAGQDYNSPLH 45 AAGQGGEQF 1587 AAGREGGNTEAF 4 AAGSPQH 3 AAGSYEQY 45 AAGTGAYEQY 19 AAGTSGNNEQF 79 AAGWNTEAF 37 I want to count the string length of the... (2 Replies)
Discussion started by: xshang
2 Replies

5. Shell Programming and Scripting

how to count string length?

Hi, Gurus, I have a requirement which need count string length. eg. abc bcde defge want to get following: abc 3 bcde 4 defge 5 :wall: thanks in advance! (6 Replies)
Discussion started by: ken002
6 Replies

6. Shell Programming and Scripting

Count line Length

I am trying to write a shell scrip that can give me the line length of a record that was in EBDIC and then converted to ASCII. Everything I try reports 1 yet the length is 2000+. I have tried echo "Line length : ${#FILE}" echo "FILE" |awk -F, '{print NF}' awk '{lenth(file)}' All I can... (11 Replies)
Discussion started by: wbshrk
11 Replies

7. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

8. UNIX for Dummies Questions & Answers

length of string

Hi lets say i have a variable output="string" how can you find the length of the string contained in this variable? i guess "wc" cannot be used. its only for files. (8 Replies)
Discussion started by: silas.john
8 Replies

9. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies

10. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies
Login or Register to Ask a Question