Sponsored Content
Full Discussion: Initials of a name
Top Forums Shell Programming and Scripting Initials of a name Post 302590154 by agama on Saturday 14th of January 2012 11:23:18 AM
Old 01-14-2012
It would be nice to know what context you are trying to do this in. As has been suggested, if you have a file of first and last names, just run a sed across the file. However, if you have a string, or two tokens, as a part of a loop in a programme, then the answer will be different. As an example, if you are working in ksh or bash this is much more efficient than running sed for each individual string:

Code:
full_name="Eric Clapton"
initials="${full_name//[a-z]/}"
echo "$full_name -> $initials"

If you need E.C. or E. C. you can do something like this:

Code:
echo "${initials/ /.}."
echo "${initials/ /. }."

---------- Post updated at 11:23 ---------- Previous update was at 11:16 ----------

Crossed posts with you...

Again, if you're using a Ksh like shell language, then you could just echo out the first characters like this:

Code:
full_name="Eric Clapton"
last="${full_name#* }"
echo  "${full_name:0:1} ${last:0:1}"

 

2 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find a file with common initials and last words

Hi, I have a requirement like i have to find out files and remove them on a daily basis. The files are generated as abc_jnfn_201404230004.csv abc_jnfo_201404230004.csv abc_jnfp_201404230004.csv abc_jnfq_201404230004.csv abd_jnfn_201404220004.csv abe_jnfn_201404220004.csv i want to... (1 Reply)
Discussion started by: Mohammed_Tabish
1 Replies

2. UNIX for Beginners Questions & Answers

Versioning up a file with initials?

I have this code that works great ... #!/bin/sh for file in "$@" do ext=${file##*.} base=${file%.*} num=${base##*v} zeroes=${num%%*} num=${num#$zeroes} #remove leading zeros, or it uses octal num=$((num+1)) base=${base%v*} ... (5 Replies)
Discussion started by: scribling
5 Replies
SWISS::Stars::EV(3pm)					User Contributed Perl Documentation				     SWISS::Stars::EV(3pm)

   new
   fromText
   toText
   sort
   addEvidence($category, $type, $initials, $attributes [, $date])
	Title:	  addEvidence

	Usage:	  $evidenceTag = $entry->Stars->EV->addEvidence($category,
								$type,
								$initials,
								$attributes
								[, $date])

	Function: adds the evidence to the EV block if it does not yet exist
		  or returns the correct evidence tag if the evidence already exists,
		  possibly with a different date.

	Args:	 $category: the evidence category. Currently one of 'A', 'C', 'I','P'.
		 $type: the evidence type
		 $initials: The initals of the person doing the update.
			    For programs this should be '-'.
		 $attributes: the attributes of the evidence
		 $date: optional. If present, it must be in standard SWISS-PROT
			date format. If not present the current date will be used.

	Returns: The correct evidence tag.

   updateEvidence($category, $type, $initials, $attributes [, $date])
	Title:	  updateEvidence

	Usage:	  $evidenceTag = $entry->Stars->EV->updateEvidence($category,
								   $type,
								   $initials,
								   $attributes
								   [, $date])

	Function: updates the evidence to the EV block to $date or inserts it
		  if it does not yet exist.

	Args:	 $category: the evidence category. Currently one of 'A', 'C', 'I','P'.
		 $type: the evidence type
		 $initials: The initals of the person doing the update.
			    For programs this should be '-'.
		 $attributes: the attributes of the evidence
		 $date: optional. If present, it must be in standard SWISS-PROT
			date format. If not present the current date will be used.

	Returns: The correct evidence tag.

Name
       SWISS::Stars::EV.pm

Description
       SWISS/Stars/EV.pm represents the evidence section within an SWISS-PROT + TrEMBL entry. See
       http://www3.ebi.ac.uk/~sp/intern/projects/evidenceTags/index.html

       For a usage example, see evTest.pl in the Swissknife package.

Inherits from SWISS::ListBase.pm
Attributes
       "list" Each element of the list describes one evidence, itself represented as an array.

perl v5.10.1							    2006-01-26						     SWISS::Stars::EV(3pm)
All times are GMT -4. The time now is 06:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy