The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to remove a character which is enclosed in Double quotes mohan_tuty UNIX for Advanced & Expert Users 3 06-16-2008 11:55 AM
charecter or number ganapati UNIX for Dummies Questions & Answers 1 01-02-2008 08:44 AM
find charecter from its ascii value. rinku Shell Programming and Scripting 2 11-20-2007 02:50 AM
Comapring files charecter by charecter using AWK/Shell Script evvander Shell Programming and Scripting 1 09-12-2007 05:44 AM
cutting columns if delimiter has more than one charecter mahabunta UNIX for Dummies Questions & Answers 9 09-14-2006 08:23 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-29-2007
rinku rinku is offline
Registered User
  
 

Join Date: May 2007
Posts: 54
cut First charecter in any string

I wannt to cut first char of any string.

str=A2465443

out put will be.
str1=A
str2=2465443.
I tried
str2=${?%srt}
str1=${str#$str2}

it is not working.
  #2 (permalink)  
Old 05-29-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,423
Code:
# var="something"
# echo ${var:0:1}
s
  #3 (permalink)  
Old 05-29-2007
suparnbector suparnbector is offline
Registered User
  
 

Join Date: May 2007
Posts: 13
try this

echo "A1234" | cut -c 2-

echo "A1234" | cut -c 0-1
  #4 (permalink)  
Old 05-29-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,355
Code:
$ str=A2465443
$ str2=${str#?}
$ str1=${str%$str2}
$ echo "<$str>=<$str1><$str2>"
<A2465443>=<A><2465443>
$
Jean-Pierre.
  #5 (permalink)  
Old 05-29-2007
praveenkumar_l's Avatar
praveenkumar_l praveenkumar_l is offline
Registered User
  
 

Join Date: May 2007
Posts: 36
Quote:
Originally Posted by rinku
I wannt to cut first char of any string.

str=A2465443

out put will be.
str1=A
str2=2465443.
I tried
str2=${?%srt}
str1=${str#$str2}

it is not working.
str2=${str#?}
str1=${str%$str2}

$ echo $str1
A
$ echo $str2
2465443
  #6 (permalink)  
Old 05-29-2007
praveenkumar_l's Avatar
praveenkumar_l praveenkumar_l is offline
Registered User
  
 

Join Date: May 2007
Posts: 36
Quote:
Originally Posted by ghostdog74
Code:
# var="something"
# echo ${var:0:1}
s
This will not work in Korn shell
  #7 (permalink)  
Old 05-29-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,794
Quote:
Originally Posted by praveenkumar_l
This will not work in Korn shell
It will work in ksh93 and some other recent Korn shell variants.

Code:
$ print ${.sh.version}
Version M-12/28/93d
$ echo ${var:0:1}
s

Another (portable ? ) variant:

Code:
printf "%.1s\n" "$var"

Last edited by radoulov; 05-29-2007 at 07:32 AM..
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0