Hi there
Someone can tell me how to get the length n of a string variable
and to extract for example the first to m-th (<n) characters substring?
Thanx
Olivier
Thanx
Olivier
Sounds like homework, but you can use ${#variable} to get a length and toQuote:> Hi there
> Someone can tell me how to get the length n of a string variable
> and to extract for example the first to m-th (<n) characters substring?
regards,
Ben
> Someone can tell me how to get the length n of a string variable
> and to extract for example the first to m-th (<n) characters
> substring?
Substring examples for the first five characters:
(destructively)
typeset -L5 string
print $string
Non-destructively:
typeset -L5 string2=$string
print $string2
or without using a second variable
print ${string%${string#?????}}
> Thanx
> Olivier
for the length:
expr length "string"
expr ${variable} : ".*"
for the substr:
expr substr "string" 1 m
echo "string" | cut -c1-m
1. How to compare String b is element of String a (substrings)
Hi,
Can someone help me with my Problem?
I am a newbie at shellscripting.
I have 2 input files.
$INPUTFILE="feed.txt"
$SPECIAL_FILE="special.txt"
-- content of feed.txt
http://some.domain/path/file
http://some.otherdomain/otherfile
http://111.222.333.444/file1
http://some.domain2/otherfile2
http://some.domain/otherpath/file3
http://111.222.333.444/spomepath/file4
..
--
-- content of special.txt
http://some.domain/
http://111.222.333.444/
..
--
-- myscript
..
..
..
special()
{
grep http $SPECIAL_FILE | while read SPECIAL_URL
do
# If SPECIAL_URL is Part of URL
# set SPECIAL=1
# This is my problem !!!!!
if [ "^$SPECIAL_URL"="$URL" ] ; then
SPECIAL=1
fi
done
grep http $INPUTFILE | while read URL
do
# call function special()
special
# if SPECIAL=1
if [ $SPECIAL == 1 ] ; then
// Do special action
echo "Special Action for: $URL is used"
...
// Reset SPECIAL
SPECIAL=-1
# normal URL
else
// Do normal stuff
echo "Everything is okay with $URL"
fi
done
My problem:
============
If an $URL is in SPECIAL_FILE than special action
has to be performed with $URL
or
if $SPECIAL_URL is part of $URL than special action
has to be performed with $URL
the comparison of the substring does not work.
Thanks for your help, hints...
Lars
2. Trouble with D-Link DFE-530TX+
3. *** NUMERIC STRINGS WHITH CSHELL OR KSHELL ??? ***
4. there are a "simple" method to manage 2 diferent domains on sendmail+rh6.0
8. Extracting substrings from strings
9. Extract a substring of n digits from a string
10. Question: How to find substring in a string?
11. extract substrings from a string
12. Removing substring from string