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 print selected pages wendyz UNIX for Dummies Questions & Answers 2 10-14-2008 12:53 PM
Print out a selected word. anakiar Shell Programming and Scripting 10 07-28-2008 04:29 AM
last char from a string broli Shell Programming and Scripting 6 12-07-2007 08:02 PM
print selected lines tonet Shell Programming and Scripting 6 10-08-2007 05:50 AM
print selected rows with awk tonet Shell Programming and Scripting 6 09-27-2007 06:23 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-21-2008
balan_mca balan_mca is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 15
Need to print only selected char in a string..?

Hi,

I want to print particular chars in a string. for example
ie.,

consider " dear,. roopa$#09%~`';'][\.@ " as the example string. Here, I want to print only alphanumeric chars..

suppose , if i want only alphanumeric... value would be "dear roopa09"
suppose , if i want some spl char(,) with alphanumeric...ans would be "dear, roopa09"
It could be anything, like only numeric chars or alphabetic or only . symbol or * symbol... anything.

plz, give ur valuable solution.

Thanx,
Balan
  #2 (permalink)  
Old 10-21-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,723
You need to read about POSIX character types in the tr man page [:alpha:], [:space:], etc.

Code:
 echo 'dear,. roopa$#09%~`][.@* ' | tr -d '[:punct:]'
This removes punctuation characters.
  #3 (permalink)  
Old 10-21-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
below script has only three options,
1> only print the digit number
2> only print the alpha
3> only print the special characters

You may amend it to fully address your desire. Hope make sense to you!

a.txt:
Code:
dear,. roopa$#09%~`';'][\.@
Code:
echo "Enter your type: 1[digit],2[alpha],3[special],4[exit]"
read type
if [ $type -eq 1 ]
then
  cat a.txt | sed 's/[^0-9]//g'
fi
if [ $type -eq 2 ]
then
  cat a.txt | sed 's/[^a-zA-Z]//g'
fi
if [ $type -eq 3 ]
then
  cat a.txt | sed -e 's/[0-9]//g' -e 's/[a-zA-Z]//g'
fi
if [ $type -eq 4 ]
then
   exit
fi
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 09:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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