Skip to content
Advertisement

How to use cut and paste commands as a single line command?

In Unix, I am trying to write a sequence of cut and paste commands (saving result of each command in a file) that inverts every name in the file(below) shortlist and places a coma after the last name(for example, bill johnson becomes johnson, bill).

here is my file shortlist:

JavaScript

I am able to cut from shortlist but not sure how to paste it on to my filenew file in same command line. Here is my code for cut:

JavaScript

result:

JavaScript

Now I want this to be pasted in my filenew file and when I cat filenew, result should look like below,

JavaScript

Please guide me through this. Thank you.

Advertisement

Answer

You could do it with a single awk:

JavaScript

I am assuming that if you don’t have a second name, you don’t want to print the comma (and you don’t have more than 2 words in the name).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement