How to interchange the places of 1st name and last name?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to interchange the places of 1st name and last name?
# 1  
Old 04-17-2013
How to interchange the places of 1st name and last name?

Code:
cat emp.lst

12  |Rob Cliff    |G.M.    
14  |Mark Rob   |Chairman

Please use awk to invert the names in the file emp.lst, i.e. the surname should be 1st and then the 1st name. There are trailing spaces even in each field making them fixed length.
# 2  
Old 04-17-2013
Can you be more clear?
# 3  
Old 04-17-2013
I want that the name as shown in the 2nd field should be a bit modified. The 2nd name should come 1st.
For example "Rob Cliff" should become "Cliff Rob"
Write program so that the complete file should be modified in the 2nd field.
i.e., the output should be:
Code:
cat emp.lst

12  |Cliff Rob    |G.M.    
14  |Rob Mark   |Chairman


Last edited by ravisingh; 04-17-2013 at 11:02 AM..
# 4  
Old 04-18-2013
How to take care of trailing spaces. I don't want to measure these and put in the printf statement. Is there any direct way that these would be taken care of
# 5  
Old 04-18-2013
What is this? Homework? Looks like it. And what is it doing in this forum (Unix for Advanced & Expert Users)?

And you haven't shown your efforts.

Mods, please move/close this thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sum the fields with 6 decimal places - getting only 2 decimal places as output

I used the below script to Sum up a field in a file based on some unique values. But the problem is when it is summing up the units, it is truncating to 2 decimals and not 6 decimals as in the input file (Input file has the units with up to 6 Decimals – Sample data below, when the units in the 2... (4 Replies)
Discussion started by: brlsubbu
4 Replies

2. Shell Programming and Scripting

Awk: Interchange the Rows and column

Hi, I have following input and want to change it to following output INPUT 01-APR-14,KB,822714 01-APR-14,MB,8133431 02-APR-14,KB,757140 02-APR-14,MB,7770368 03-APR-14,KB,815427 03-APR-14,MB,7590511 04-APR-14,MB,7529895 04-APR-14,KB,779561 05-APR-14,MB,8151537 05-APR-14,KB,809675 ... (6 Replies)
Discussion started by: siramitsharma
6 Replies

3. Shell Programming and Scripting

Easy edit problem: interchange columns

hi; my file1.txt: cell137 1 cell337 1 cell355 1 cell355 3 cell360 1 cell360 2 cell360 3 my file2.txt: ... cell137 1 20.64.1.97 cell137 2 20.64.1.97 cell137 3 20.64.1.97 ... cell337 1 20.64.1.113 cell337 2 20.64.1.113 cell337 3 20.64.1.113 (4 Replies)
Discussion started by: gc_sw
4 Replies

4. Shell Programming and Scripting

vi editor - interchange two lines

Hi, I have a quick question regarding vi editor.Is it possible to interchange two lines in vi editor without using the possibilites of cut-paste,copy paste etc? Your help is appreciated! Regards Dileep (4 Replies)
Discussion started by: DILEEP410
4 Replies

5. Shell Programming and Scripting

How to interchange the lines

Hi, I want to know that, how to inter change the lines. In the following file two line are there first one is conatin PD next line PY. But i want to first line PY and next line PD. My file structure is like this: TI Electronic Publishing AU Robert PD... (5 Replies)
Discussion started by: shankarao
5 Replies
Login or Register to Ask a Question