1

I'm currently learning CentOS and need some assistance if possible. I have a file UserNameList.lst, which is used to generate user accounts. The content of the file is below

Josh, Adams, Joshadams@gmail.com
Henry, Ford, HFord@gmail.com

I need to output a txt file which looks like this. (basically combining column 2 and 1 to make a single column)

Adams Josh
Ford Henry

I tried using the command

cut -d "," -f 1 >> Last.txt
cut -d "," -f 2 >> First.txt
paste First.txt Last.txt >> full

which outputs

Adams    Josh
Ford     Henry

Is there a simpler way to do this?

1 Answer 1

1

This is best suited for awk

$ cat ip.txt 
Josh, Adams, Joshadams@gmail.com
Henry, Ford, HFord@gmail.com

$ awk -F"[ ,]+" '{print $2, $1}' ip.txt 
Adams Josh
Ford Henry
  • -F"[ ,]+" field separator is one or more of space and , characters
  • Then simply print second and first columns
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.