Sponsored Content
Top Forums Shell Programming and Scripting Compare string length to a number Post 302979960 by RavinderSingh13 on Monday 22nd of August 2016 11:34:58 AM
Old 08-22-2016
Quote:
Originally Posted by rajneesh4U
Hi,
I want to compare strings length to a number but i am getting error. I want first name should be length of 8.
Please help.
Code:
#bin !/bin/bash
clear
echo -n "Enter name "
read name
IFS=_
ary=($name)
for key in "${!ary[@]}"; do echo "$key${ary[$key]}"; done
##First name should be equal to 8 digits
var=${ary[0]}
l1=${#var}
echo "$l1"
if [ "$l1" == 8]
then 
echo "Length Matching"
else
echo "Not Matching"
if

Hello rajneesh4U,

As a starter, could you please change if [ "$l1" == 8] to if [[ "$l1" == 8 ]] and let us know how it goes then(Not tested complete script though).

Thanks,
R. Singh
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

how can i compare te length of the string

how can i campare te length of the string $var = unix if ( $var -eq 4 ) then.. is it right (6 Replies)
Discussion started by: mail2sant
6 Replies

4. Shell Programming and Scripting

How to Compare two files depend on line length Chars

I need to compare two files with exactly same length as example: - File1 contain 500 records with length of 640 chars of each line. File2 contain 1500 records with length of 640 chars of each line. I need get an output to be written in File3 which will contain 1000 records difference. but... (4 Replies)
Discussion started by: elj3dah
4 Replies

5. 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

6. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

7. UNIX for Dummies Questions & Answers

compare 2 very large lists of different length

I have two very large datasets (>100MB) in a simple vertical list format. They are of different size and with different order and formatting (e.g. whitespace and some other minor cruft that would thwart easy regex). Let's call them set1 and set2. I want to check set2 to see if it contains... (2 Replies)
Discussion started by: uiop44
2 Replies

8. Shell Programming and Scripting

[awk]compare a number in a string with a list

Hi, I have a program written in awk and I want to extend it to do another task. My program is a list of CVS log reports of a repository. For each file, I have some fields. One of the fields is the comment field. I want to know how I can check if a comment (which is a free text field)... (8 Replies)
Discussion started by: sandeepk1611
8 Replies

9. Shell Programming and Scripting

Pass column number as variable to awk and compare with a string.

Hi All, I have a file test.txt. Content of test.txt : 1 vinay se 2 kumar sse 4 kishore tl I am extracting the content of file with below command. awk '$2 ~ "vinay" {print $0}' test.txt Now instead of hardcoding $2 is there any way pass $2 as variable and compare with a... (7 Replies)
Discussion started by: Girish19
7 Replies

10. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies
BOOLVAL(3)								 1								BOOLVAL(3)

boolval - Get the boolean value of a variable

SYNOPSIS
boolean boolval (mixed $var) DESCRIPTION
Returns the boolean value of $var. PARAMETERS
o $var - The scalar value being converted to a boolean. RETURN VALUES
The boolean value of $var. EXAMPLES
Example #1 boolval(3) examples <?php echo '0: '.(boolval(0) ? 'true' : 'false')." "; echo '42: '.(boolval(42) ? 'true' : 'false')." "; echo '0.0: '.(boolval(0.0) ? 'true' : 'false')." "; echo '4.2: '.(boolval(4.2) ? 'true' : 'false')." "; echo '"": '.(boolval("") ? 'true' : 'false')." "; echo '"string": '.(boolval("string") ? 'true' : 'false')." "; echo '"0": '.(boolval("0") ? 'true' : 'false')." "; echo '"1": '.(boolval("1") ? 'true' : 'false')." "; echo '[1, 2]: '.(boolval([1, 2]) ? 'true' : 'false')." "; echo '[]: '.(boolval([]) ? 'true' : 'false')." "; echo 'stdClass: '.(boolval(new stdClass) ? 'true' : 'false')." "; ?> The above example will output: 0: false 42: true 0.0: false 4.2: true "": false "string": true "0": false "1": true [1, 2]: true []: false stdClass: true SEE ALSO
floatval(3), intval(3), strval(3), settype(3), is_bool(3), Type juggling. PHP Documentation Group BOOLVAL(3)
All times are GMT -4. The time now is 03:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy