Monday, 9 July 2012

Separating username and password using cut command in UNIX.


I was writing a script in UNIX where I got to come across a scenario, to separate user name and Password. The string was apps/apps where first part precede the / was the user name and the apps succeeds the / was the Password. I googled it and came to know about this CUT command.
ID=apps/apps
LOGIN=`echo $ID | cut -d"/" -f1`
PWD=`echo $ID | cut -d"/" -f2`

The echo $ID will have the string, CUT is the Key work for this command, -d for delimiter / and –f1 will store the first part of the string. Similarly –f2 will store the second part of the string.

No comments:

Post a Comment