Shell scripts are easier to write but they lack the features provided by a programming language like python. But instead python can be used within shell scripts. Here are two examples. 1. To get the file name ‘File’ from the full path ‘Path’: File=`python -c "print '$Path'.split('/')[-1]"` 2. To get the directory ‘Dir’ from the full path ‘Path’ of file ‘File’: Dir=`python -c "print '$Path'.rstrip(str('$File'))"`
Python has a ‘re’ module to handle regular expressions. Here are some examples. >>> import re #Example 1: To extract the contents within double quotes in a string >>> s = 'customer name is "FirstName LastName"' >>> re.findall('".*"',s) ['"FirstName LastName"'] #The result is a list #Example 2: To extract the individual words from a combined word like ‘FirstName’ >>> s = 'FirstName' >>> re.findall('[A-Z][a-z]+',s) ['First', 'Name'] #The result is a list. >>> ''.join(re.findall('[A-Z][a-z]+',s)) 'FirstName' #To get the string from the list #Example 3: To replace all numbers with a ‘.’ suffix’ >>> s = '1 one 11 eleven' >>> re.sub("(\d)( )","\\1.\\2",s) '1. one 11. eleven'
GITHUB: To init github type the command followed by repository name (say TCP): git init TCP.git Then cd to this git directory cd TCP.git Then add the remote repository: git remote add origin https://github.com/user-name/TCP.git To get the files from the TCP.git repository: git pull origin master After Changing files, commit them: git add . git commit -a This will open a nano editor window. Remove comment in modified file lines and save the file by pressing escape and "Y". To update the repository: git push origin master This will ask for username and password. To check status: git status
SSH with no password: Here is a two step process to use SSH/SCP and access remote machines without password. 1. Generate a public/private rsa key pair in the local machine (client): Command: ”ssh-keygen“ The public key will be saved in a file at ~/.ssh/id_rsa 2. Copy the id to the remote machine (server): Command: “ssh-copy-id UserName@ServerAddress“ Thats all need to do. Now you can try “ssh UserName@ServerAddress” and it should login without asking password. Same with scp command.