csh: printing substring of a string

csh: printing substring of a string

Post by David SEGON » Fri, 01 Mar 1996 04:00:00



Hello,

    Jean-Paul> How can I get a substring of a string with csh for
    Jean-Paul> example the first 5 characters of a string of 10 chars

        Here is one solution for your problem!

------------------------------------------
#!/bin/csh

echo $1
echo $1 | awk '{ print substr($1,1,5) }'
------------------------------------------

    Jean-Paul> Jean-Paul
--
--
* Pessimist: Can't get any worse... Optimist: It can, it can!!! (Unknown author)

                Tel:33-1-47527131 - fax:33-1-47527022
 IFP - DIMA - 1,4 Rue du bois Preau - 92506 Rueil Malmaison - France

 
 
 

csh: printing substring of a string

Post by Bernhard Rossbot » Tue, 05 Mar 1996 04:00:00




> : Hello,

> :     Jean-Paul> How can I get a substring of a string with csh for
> :     Jean-Paul> example the first 5 characters of a string of 10 chars

>      How about:

>      echo <string>|cut -l1-5

Save a process per day:

expr "String" : '\(.....\)'

Barny :-{)
--
       ___  /   ___  /   ___  /    Bernhard Rossboth :-{)
      /    /   /    /   /    /     Alcatel Austria AG
     ___  /   ___  /   ___  /      A-1210 Wien, Scheydgasse 41
    /    /   /    /   /    /       Tel: +43-1-27722-2262
   /  __/ __/  __/ __/  __/        Fax: +43-1-27722-171
                                   E-Mail:


 
 
 

1. csh: how to get substring, or replace string with null?

I'm using the C shell (csh) on Solaris 2.8. I have a variable, called newf and
I need to shave off the first 4 characters (which are always the same). Say
newf='DIV_12345'. I need newf to be '12345'. How can I get a replace 'DIV_'
with null?

Thanks.

--
Freezone Freeware and Free Delphi Components
http://freezone.darksoft.co.nz http://chuckr.bravepages.com
http://www.bdsg.com/resources

2. Error Compiling Modules 1.1.87

3. How to find a substring in a csh string

4. RingCentral Fax

5. How to compare String b is element of String a (substrings)

6. A few questions from a newbie

7. substring from string

8. Newly compiled kernel...

9. Extracting substrings from strings

10. Extract a substring of n digits from a string

11. Kshell: length of a string and substring

12. Question: How to find substring in a string?

13. extract substrings from a string