Thursday, July 23, 2015

Grep between two words in string

Say from the string "Age: = 24 years", you want to extract the value 24. Grep can be used to search for a pattern between two words. Here is the grep command for that:
echo "Age: = 24 years" | grep -P -o '(?<=Age: = ).*(?= years)'

Wednesday, July 22, 2015

Using iTunes & iPhone in Virtual-Box Windows from Ubuntu Linux host

Using iTunes to access iPhone in Ubuntu is not possible but you can do it with a Windows Virtual Machine.

#1. Install Virtualbox from Oracle in Ubuntu.

#2. In Ubuntu add user to vboxusers group by this command:  
sudo gpasswd -a $USER vboxusers

#3. Connect your iPhone to the Ubuntu USB port. 

#4. Within Virtualbox install Windows-7

#5. Once installed run Windows-7 and install Guest Additions Extension Pack.

#6. Reboot the Windows-7 Virtual Machine and from the Devices menu on top, select USB and check the "Apple Inc". 

#7. Install iTunes within Windows-7. Run iTunes and it will detect your iPhone. 

Monday, July 6, 2015

Range or Sequence in Shell Script

Following is an example to print numbers 1 to 20 in a shell script. The numbers below 10 need to be printed with 2 digits like 01..09 

for i in $(seq 20) 
if [ $i -le 9 ] 
then echo 0$i
else echo $i