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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh - test if string contains alphanumeric... tugger Shell Programming and Scripting 3 10-16-2007 04:23 AM
alphanumeric comparision rakeshou Shell Programming and Scripting 3 09-27-2007 11:32 AM
With Regex Spliting the string into Alphanumeric and Numeric part ozgurgul Shell Programming and Scripting 1 06-30-2007 09:52 AM
String Operations Rohini Vijay Shell Programming and Scripting 9 04-21-2006 11:32 AM
matching alphanumeric string sskb Shell Programming and Scripting 4 12-12-2001 10:48 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 01-05-2007
lakshmikanth lakshmikanth is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 6
Unhappy AlphaNumeric String Operations

Hi

I am writing a ksh

I have a string of general format

A12B3456CD78

the string is of variable length

the string always ends with numbers (here it is 78.. it can be any number of digits may be 789 or just 7)

before these ending numbers are alphabets (here it is CD can even be C alone or CDX ..that is length can be varied)

before the CD is a string of variable length that always ends in digits here A12B3456 ....

i want to extract each of these seperately ..
ie
part one A12B3456
part two CD
part three 78

this is a bit complicated for me ... plz help me out
  #2 (permalink)  
Old 01-05-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
echo A12B3456CD78 | sed "s/\([0-9]*\)$/\\
\1/" | sed "1 s/\([a-zA-Z]*\)$/\\
\1/"
  #3 (permalink)  
Old 01-05-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Code:
[/tmp]$ cat ./try.ksh
#! /bin/ksh

in=A12B3456CD78

f3=$(echo $in | tr '[A-Z]' ' ')
f3=${f3##* }
in=${in%$f3}
f2=$(echo $in | tr '[0-9]' ' ')
f2=${f2##* }
f1=${in%$f2}
echo "$f1"
echo "$f2"
echo "$f3"

[/tmp]$ ./try.ksh
A12B3456
CD
78
[/tmp]$
  #4 (permalink)  
Old 01-05-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,932
Code:
# !/opt/third-party/bin/zsh
                                                                                 
str="A12B3456CD78"
                                                                                 
only_num=$(echo $str | tr '[A-Za-z]' ' ' | awk '{print $NF}')
only_alpha=$(echo $str | tr '[0-9]' ' ' | awk '{print $NF}')
echo $str $only_num $only_alpha | awk '{ print (substr ($0,0,length($1) - ( length($2) + length($3) ))), "\n", $2, "\n", $3 }'
                                                                                 
exit 0
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 07:25 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