Sponsored Content
Top Forums UNIX for Dummies Questions & Answers tcsh - test for character in string for if then Post 302545843 by deepstructure on Tuesday 9th of August 2011 05:10:24 PM
Old 08-09-2011
Hey yazu,

Thanks for that solution - that at least either gives me the result or an empty string. Now I need to do a search to figure out how to test the variable for a null value...

---------- Post updated at 04:10 PM ---------- Previous update was at 03:58 PM ----------

O.k, a combo of yazu's solution and a null string check does the job:

Code:
foreach ITEM ($DIRLIST)
	set SERVER			= `echo $ITEM | awk -F/ '{print $3}'`
	set SERVER_TARGET 	= `echo $ITEM | awk -F/ '{print "/"$2"/"$3"/"}'`
	set SOURCE			= `echo $ITEM | awk -F$SERVER_TARGET '{print $2}'`
	set SLSH_CNT_PRE	= `echo $ITEM | awk -F/ '{print NF-1}'`
	@ SLSH_CNT		= $SLSH_CNT_PRE + 1
	set LAST_PART		= `echo $ITEM | awk -v var1="$SLSH_CNT" -F/ '{print $var1}'`
	set TESTER  = `echo $LAST_PART | awk -F. 'NF > 1 {print $1}'`
	echo "----- $ITEM Variables -----"
	echo "slash count is   :$SLSH_CNT"
	echo "last part is     :$LAST_PART"
	if ( ${%TESTER} == 0 ) then
		echo "$LAST_PART does not have a period in it."
	else
		echo "$LAST_PART has a period in it."
	endif
	echo ""
end

which when run on the following list:

/Volumes/projects/_library/assets/textures/SeaLife/seaweed/seaweed01_base_v2.jpg
/Volumes/projects/_library/assets/digital-doubles/dd_sean/txt/DD_sean_splint_color.exr
/Volumes/projects/es/0697/3d/cam/_PUBLISH

produces the following result:

----- /Volumes/projects/_library/assets/textures/SeaLife/seaweed/seaweed01_base_v2.jpg Variables -----
slash count is :10
last part is :seaweed01_base_v2.jpg
seaweed01_base_v2.jpg has a period in it.

----- /Volumes/projects/_library/assets/digital-doubles/dd_sean/txt/DD_sean_splint_color.exr Variables -----
slash count is :10
last part is SmilieD_sean_splint_color.exr
DD_sean_splint_color.exr has a period in it.

----- /Volumes/projects/es/0697/3d/cam/_PUBLISH Variables -----
slash count is :9
last part is :_PUBLISH
_PUBLISH does not have a period in it.


Thanks!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Test return character.

Hi, in my korn shell I have this code: typeset -uL1 rc read rc?"Insert Y=Yes (default) or N=No >>" If I press enter without value I wish to set rc=Y. This is my default. This test: if ] then .... Do not work. I hope in your help. Thanks in advance. Regards, Giovanni (3 Replies)
Discussion started by: gio123bg
3 Replies

2. Shell Programming and Scripting

Matching a choice of character in test command

Hi ] && exit 0 Although it, the $answer, is 'y', the test operation returns true. && exit 0 This works but I want to do multiple choice matching. I don't want to do like: Please help (2 Replies)
Discussion started by: lalelle
2 Replies

3. Shell Programming and Scripting

escape character in tcsh

Hello, I wanted to display command with echo like this in tcsh. output should be "//'test.test1.test2'" (" at both ends also required in output) Please help me. (1 Reply)
Discussion started by: balareddy
1 Replies

4. Shell Programming and Scripting

Korn: How to loop through a string character by character

If I have a string defined as: MyString=abcde echo $MyString How can I loop through it character by character? I haven't been able to find a way to index the string so that I loop through it. shew01 (10 Replies)
Discussion started by: shew01
10 Replies

5. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

6. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

7. Shell Programming and Scripting

Pass string to nummerical value in tcsh

I want to compare two values for Value A and ValueB, however, they are strings, so is there a way I could them into numberical value in tcsh #! /bin/tcsh set ValueA = `awk '{print $6}' out0File` set ValueB = `awk '{print $6}' out1File` set Delta = `expr $ValueA - $ValueB` ... (1 Reply)
Discussion started by: proteinpi
1 Replies

8. Shell Programming and Scripting

Test command with special character not work

Hi all, Case 1 : A=88^M && echo "PASS" Result: PASS Case 2: A=88 && echo "PASS" Result: PASS I would like to know why Case 1 and Case 2 got the same result? What make ^M ignored ? Thanks in advance. (6 Replies)
Discussion started by: montor
6 Replies

9. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

10. Shell Programming and Scripting

Tcsh, using " in a string variable

Hallo, I try to write a tcsh-script which works with ImageMagick. The following command line works perfectly: convert a.tif -pointsize 80 -draw " gravity NorthWest fill black text 0,12 a " b.tif I use the following code in a script (it is a minimal example to show the problem): ... (3 Replies)
Discussion started by: DanielDD
3 Replies
Tcl_UtfToUpper(3)					      Tcl Library Procedures						 Tcl_UtfToUpper(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_UniCharToUpper, Tcl_UniCharToLower, Tcl_UniCharToTitle, Tcl_UtfToUpper, Tcl_UtfToLower, Tcl_UtfToTitle - routines for manipulating the case of Unicode characters and UTF-8 strings. SYNOPSIS
#include <tcl.h> Tcl_UniChar Tcl_UniCharToUpper(ch) Tcl_UniChar Tcl_UniCharToLower(ch) Tcl_UniChar Tcl_UniCharToTitle(ch) int Tcl_UtfToUpper(str) int Tcl_UtfToLower(str) int Tcl_UtfToTitle(str) ARGUMENTS
int ch (in) The Tcl_UniChar to be converted. char *str (in/out) Pointer to UTF-8 string to be converted in place. _________________________________________________________________ DESCRIPTION
The first three routines convert the case of individual Unicode characters: If ch represents a lower-case character, Tcl_UniCharToUpper returns the corresponding upper-case character. If no upper-case character is defined, it returns the character unchanged. If ch represents an upper-case character, Tcl_UniCharToLower returns the corresponding lower-case character. If no lower-case character is defined, it returns the character unchanged. If ch represents a lower-case character, Tcl_UniCharToTitle returns the corresponding title-case character. If no title-case character is defined, it returns the corresponding upper-case character. If no upper-case character is defined, it returns the character unchanged. Title-case is defined for a small number of characters that have a different appearance when they are at the beginning of a capitalized word. The next three routines convert the case of UTF-8 strings in place in memory: Tcl_UtfToUpper changes every UTF-8 character in str to upper-case. Because changing the case of a character may change its size, the byte offset of each character in the resulting string may differ from its original location. Tcl_UtfToUpper writes a null byte at the end of the converted string. Tcl_UtfToUpper returns the new length of the string in bytes. This new length is guaranteed to be no longer than the original string length. Tcl_UtfToLower is the same as Tcl_UtfToUpper except it turns each character in the string into its lower-case equivalent. Tcl_UtfToTitle is the same as Tcl_UtfToUpper except it turns the first character in the string into its title-case equivalent and all fol- lowing characters into their lower-case equivalents. BUGS
At this time, the case conversions are only defined for the ISO8859-1 characters. Unicode characters above 0x00ff are not modified by these routines. KEYWORDS
utf, unicode, toupper, tolower, totitle, case Tcl 8.1 Tcl_UtfToUpper(3)
All times are GMT -4. The time now is 10:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy