How to separate First,Middle and Last Name from Full name


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to separate First,Middle and Last Name from Full name
# 1  
Old 08-21-2011
Question How to separate First,Middle and Last Name from Full name

How to separate First,Middle and Last Name from Full Name?
For Example:
I/O :- 1) Ashok Kumar
Requied Output:
First Name:Ashok
Middle Name:
Last Name:Kumar
I/O :- 2) Ashok K Kumar
Requied Output:
First Name:Ashok
Middle Name:K
Last Name:Kumar
I/O :- 3) Ashok K R Kumar
Requied Output:
First Name:Ashok
Middle Name:K R
Last Name:Kumar

I want all these within single script.In short,i want to separate first,middle and last name. Smilie
# 2  
Old 08-21-2011
see if this work for all set of input ...for me it worked on the ones u gave

Code:
 
$ cat test.txt
Ashok Kumar
Ashok A K Kumar
Ashok K KUMAR
$


Code:
 
$ cat ./script.ksh
while read first i
do
last=`echo $i | /usr/bin/awk '{print $NF}'`
middle=`echo $i | /usr/bin/awk '{NF=NF -1; $1=$1 ; print}'`
echo "First name : $first"
echo "Middle name : $middle"
echo "Last name : $last"
done <test.txt
$



Output

$ ./script.ksh
First name : Ashok
Middle name : Kumar
Last name : Kumar
First name : Ashok
Middle name : A K
Last name : Kumar
First name : Ashok
Middle name : K
Last name : KUMAR
$
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. AIX

100% Inode full with only 67% FS full.

AIX Version 6.1 and 7.1. I understand that when the OS initially creates the FS and inodes, its pretty strict, but not always tuned to a 1:1 ratio. I see the same thing when adding a whole disk LV to a separate device. It seems that when we expand a filesystem the inodes don't get tuned... (5 Replies)
Discussion started by: mrmurdock
5 Replies

2. Shell Programming and Scripting

Adding new column in the middle

Hi , I need to add few new columns in existing file .Any help would be great ex: existing file name,typ,add,dept New file(com1,sal are new) name,com1,type,sal,add,dept Thanks, mohan (1 Reply)
Discussion started by: mohan705
1 Replies

3. Shell Programming and Scripting

How to extract strings from full path when full path is not fixed

/Path/snowbird9/nrfCompMgrRave1230100920.log.gz:09/20/2010 06:14:51 ERROR Error Message. /Path/snowbird6/nrfCompMgrRave1220100920.log.gz:09/20/2010 06:14:51 ERROR Error Message. /Path/snowbird14/nrfCompMgrRave920100920.log.gz:09/20/2010 06:14:51 ERROR Error Message.... (0 Replies)
Discussion started by: Shirisha
0 Replies

4. Shell Programming and Scripting

add a word in the middle

I have a file where in I need to add gctunit1/gtdivcompebb1/ after the = sign for example: gtfix31/gctunit_gtdivcompebb1/csclkswcompbypassstepgnnnh = gctunit1/gtdivcompebb1/csclkswcompbypassstepgnnnh (3 Replies)
Discussion started by: pitagi
3 Replies

5. Shell Programming and Scripting

How to process from middle of a file?

Hi There. I have a file like this . a nnnn sds b ssss fdefd c sdfd dsfd sdfds ... ... Summary t1 t2 t3 t4 s1 s2 s3 s4 f1 f2 f3 f4 .. How to use awk to begin process this file from the line that contains "Summary"? Thanks! louis (12 Replies)
Discussion started by: javacore
12 Replies

6. Shell Programming and Scripting

change RS in the middle

in AWK, how can I change the RS (record separator) in the middle of awk command. for example: gawk 'NR==FNR { key++;next }; RS="?"; $1 in key' file1 file2 in above, I put RS="?" in the middle to change the value of RS to "?" right after the file1 has been processed. when it begins to... (2 Replies)
Discussion started by: fredao
2 Replies

7. Shell Programming and Scripting

How to 'sed' the middle line?

Hi, If I have 90 lines and I want to print the 45th line, is there a quick sed command for this? thx. (7 Replies)
Discussion started by: g_jumpin
7 Replies

8. UNIX for Dummies Questions & Answers

Selecting the middle date!

Hi everyone really need some help with this one. Ive to write a script where the middle date has to be checked and made sure that it is the current date. 281220032812200328122003 This is the format ive to check the date in the middle is the current date. Can anyone help me with this... (14 Replies)
Discussion started by: vcardo10
14 Replies
Login or Register to Ask a Question