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
MINC_MODIFY_HEADER(1)						 MINC User's Guide					     MINC_MODIFY_HEADER(1)

NAME
minc_modify_header - modify the attributes in the header of a minc file SYNOPSIS
minc_modify_header [<options>] <file>.mnc DESCRIPTION
Minc_modify_header allows the modification, insertion or deletion of attributes in a minc file. If possible, the file is modified in place, without copying the data. This will happen when inserting (modifying) an attribute that already exists and that ends up being the same length or shorter in the new file. If an attribute is deleted or lengthened, then a complete copy of the data is made, resulting in a com- pletely new file that replaces the original. If the file is compressed, then it is first decompressed into a file whose name is either the same as that of the original file up to the ".mnc" extension or the same minus the compression extension (".bz", ".bz2", ".gz", ".Z", ".z" or ".zip"). The new file will not be re- compressed. Care is taken to completely overwrite any existing attribute when inserting a new attribute so that information is guaranteed to be removed from the file. OPTIONS
Note that options can be specified in abbreviated form (as long as they are unique) and can be given anywhere on the command line. -sinsert var:attr=value Insert a string attribute into the header. If the attribute does not exist or the new string is longer than the existing one, then all data in the file will be copied. -sappend var:attr=value Similar to -sinsert, but appends the string to the attribute's value. If the attribute already exists it must be of string type. -dinsert var:attr=value(,...) Insert a double precision attribute into the header. If the attribute does not exist or the new attribute is longer than the exist- ing one, then all data in the file will be copied. A comma-separated array of values can be specified. -dappend var:attr=value(,...) Similar to -dinsert, but appends the list of double precision values to the attribute's value. If the attribute already exists it must be of double precision type. -delete var:attr Delete an attribute from the header. USE OF THIS OPTION WILL FORCE A COMPLETE COPY OF ALL DATA TO BE MADE. Use -sinsert with an empty string to delete information without copying data (the attribute will continue to exist). -help Print summary of command-line options and exit. -version Print the program's version number and exit. EXAMPLES
: To replace the patient name with an identifier string: minc_modify_header file.mnc -sinsert 'patient:full_name=C02-F0023' To delete the patient name completely (forcing a copy of all data): minc_modify_header file.mnc -delete 'patient:full_name' To hide the patient name without copying data, assuming that we know that the attribute exists (the attribute will remain in the file, but it will be empty): minc_modify_header file.mnc -sinsert 'patient:full_name=' AUTHOR
Peter Neelin COPYRIGHTS
Copyright (C) 1995 by Peter Neelin $Date: 2004-05-25 21:33:11 $ MINC_MODIFY_HEADER(1)
All times are GMT -4. The time now is 06:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy