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
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep is used to invoke the grep on compress'ed or gzip'ed files. All options specified are passed directly to grep. If no file is speci- fied, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If zgrep is invoked as zegrep or zfgrep then egrep or fgrep is used instead of grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. For example: for sh: GREP=fgrep zgrep string files for csh: (setenv GREP fgrep; zgrep string files) AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), egrep(1), fgrep(1), zdiff(1), zmore(1), znew(1), zforce(1), gzip(1), gzexe(1) ZGREP(1)
All times are GMT -4. The time now is 07:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy