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
echo(1B)					     SunOS/BSD Compatibility Package Commands						  echo(1B)

NAME
echo - echo arguments to standard output SYNOPSIS
/usr/ucb/echo [-n] [argument] DESCRIPTION
echo writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. echo is useful for producing diagnostics in command files and for sending known data into a pipe, and for displaying the contents of envi- ronment variables. For example, you can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows: o echo your current-working-directory's full pathname o pipe the output through tr to translate the path's embedded slash-characters into space-characters o pipe that output through wc -w for a count of the names in your path. example% /usr/bin/echo "echo $PWD | tr '/' ' ' | wc -w" See tr(1) and wc(1) for their functionality. The shells csh(1), ksh(1), and sh(1), each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. /usr/ucb/echo and csh's echo() have an -n option, but do not understand back-slashed escape characters. sh's echo(), ksh's echo(), and /usr/bin/echo, on the other hand, understand the black-slashed escape characters, and ksh's echo() also understands a as the audible bell character; however, these commands do not have an -n option. OPTIONS
-n Do not add the NEWLINE to the output. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), ksh(1), sh(1), tr(1), wc(1), attributes(5) NOTES
The -n option is a transition aid for BSD applications, and may not be supported in future releases. SunOS 5.11 3 Aug 1994 echo(1B)
All times are GMT -4. The time now is 10:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy