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
matching a letter in a word Furqan_79 Shell Programming and Scripting 2 06-05-2008 01:45 PM
How to filter the words, if that word contains the expected letter venu_eie UNIX for Advanced & Expert Users 3 03-19-2008 01:00 PM
Read line by line not word by word vadharah Shell Programming and Scripting 6 03-02-2008 02:29 PM
how to move word by word on command line pbsrinivas UNIX for Dummies Questions & Answers 1 11-23-2007 06:17 AM
Can a shell script pull the first word (or nth word) off each line of a text file? tricky Shell Programming and Scripting 5 08-17-2006 06:29 AM

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

Join Date: Apr 2008
Posts: 21
First letter of each Word from a line

Hello All,

I am new to UNIX, how do i get the First letter of each Word from a line in shell scripting.

For Example
line = "The Jack In The Box"

I want to reterive The letters T for The, J from Jack, I from In, T from The and B from Box.

and store in another string.

Can anyone please help out.

Thanks in Advance

Rahul
  #2 (permalink)  
Old 04-15-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is offline Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,953
is this homework? if so, plz read the rules!

Simple rules of the UNIX.COM forums:
  #3 (permalink)  
Old 04-15-2008
maxmave maxmave is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 21
No this is not a homework, i was wondering how to do this.

Thanks

Rahul
  #4 (permalink)  
Old 04-15-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
one way
Code:
echo "jack in the box" | tr -s ' '  '\n' | cut -c 1
  #5 (permalink)  
Old 04-15-2008
maxmave maxmave is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 21
Thanks Jack for the snippet.

Regards

Rahul
  #6 (permalink)  
Old 04-15-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by maxmave View Post
line = "The Jack In The Box"

I want to reterive The letters T for The, J from Jack, I from In, T from The and B from Box.

and store in another string.

Code:
line="The Jack In The Box"
firstletters=$( set -f; printf "%c " $line )
[QUOTE]
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 04:29 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