Sponsored Content
Top Forums Shell Programming and Scripting Verify the variable has "space" or not? Post 302669681 by methyl on Wednesday 11th of July 2012 08:02:43 AM
Old 07-11-2012
Please post what Operating System you have and what Shell you use.

If you are validating a field, it is better to work from a list of valid characters.
What are the valid characters?


If you just want to count the characters, one trick is to delete everything except that character, then count what's left:

Code:
# Counting space characters
echo "abc def"|tr -cd " "|wc -c
1
echo "abcdef"|tr -cd " "|wc -c
0
# Counting "a" characters
echo "abc def"|tr -cd "a"|wc -c
1
echo "abcdef"|tr -cd "a"|wc -c
1


@pamu
The grep -c command counts lines not characters.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

verify ftp status is "good"

Hello, From reading prior "threads", my script looks like this: #!/bin/ksh -x ftpresults=`ftp -nv $ftphost1 << EOB user $ftpuser $ftppwd put $ftp_file $ft put $ftp_file $ft1 bye EOB` ftp_ctr=`echo $ftpresults | grep "226 Transfer complete" | wc -l`... (4 Replies)
Discussion started by: blt123
4 Replies

2. Solaris

"Error for Command: verify"

I have a raid 5 configuration in a A3500 rack, manager by raid manager. This morning I found this messages in a /vad/adm/messages": Sep 10 04:33:57 zion scsi: WARNING: /sbus@3,0/SUNW,socal@2,0/sf@1,0/ssd@w200200a0b80735d3,4 (ssd11): Sep 10 04:33:57 zion Error for Command: verify ... (1 Reply)
Discussion started by: bonovox
1 Replies

3. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

4. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

5. Shell Programming and Scripting

if [ "variable" = "numerical-range" ]; then

been a while so i'm a bit rusty and need a little help. writing a script that needs to compare $EXECHOST(a number) against a numerical range and then set a value. below isn't working but should give you folks an idea of my goal: if ; then echo "This is a 32B machine, exiting..." if ;... (4 Replies)
Discussion started by: crimso
4 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

8. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

9. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies
CTYPE_SPACE(3)								 1							    CTYPE_SPACE(3)

ctype_space - Check for whitespace character(s)

SYNOPSIS
bool ctype_space (string $text) DESCRIPTION
Checks if all of the characters in the provided string, $text, creates whitespace. PARAMETERS
o $text - The tested string. RETURN VALUES
Returns TRUE if every character in $text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters. EXAMPLES
Example #1 A ctype_space(3) example <?php $strings = array('string1' => " ", 'string2' => " arf12", 'string3' => ' '); foreach ($strings as $name => $testcase) { if (ctype_space($testcase)) { echo "The string '$name' consists of all whitespace characters. "; } else { echo "The string '$name' does not consist of all whitespace characters. "; } } ?> The above example will output: The string 'string1' consists of all whitespace characters. The string 'string2' does not consist of all whitespace characters. The string 'string3' does not consist of all whitespace characters. NOTES
Note If an integer between -128 and 255 inclusive is provided, it is interpreted as the ASCII value of a single character (negative val- ues have 256 added in order to allow characters in the Extended ASCII range). Any other integer is interpreted as a string contain- ing the decimal digits of the integer. SEE ALSO
ctype_cntrl(3), ctype_graph(3), ctype_punct(3). PHP Documentation Group CTYPE_SPACE(3)
All times are GMT -4. The time now is 03:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy