Showing posts with label awk. Show all posts
Showing posts with label awk. Show all posts

Wednesday, January 2, 2013

Want to apply just a part of your patch(Only on few files or even a few lines)?


Starting tag = MY_PORTION_START
Ending tag = MY_PORTION_END
You have to insert these tags into your patch file depends on your need.

Saturday, March 26, 2011

Command-line dictionary

It just parse the website wordnetweb and extract the meaning of the word/phrase given. You need lynx to run this script successfully.


References:
http://ubuntuforums.org/showthread.php?t=371482
http://wordnetweb.princeton.edu/perl/webwn

Wednesday, September 15, 2010

awk - One of the best tools in linux

I was searching for a tool/command in linux to remove all the duplicate lines from a file without sort the lines. And i came across this link (see the link below)...Its really amazing. We can do lots and lots of things using awk. Its one of the mostpowerful tools for file/string processing. I hope it will be useful for most of the software developers and testers. One more good thing is that awk is available for windows too.

Link: http://kaneda.bohater.net/faq/awk1line.txt.
The latest version of this file is here.

Wednesday, May 12, 2010

Script to mount partitions from image file in linux

#!/bin/bash

usage ()
{
    cat <<EOF
Usage: $(basename $0) <image file>
EOF
exit 1;
}

# Check for the input argument
if [ $# -ne 1 ]; then
    usage
fi

sfdisk -l -uS $1 

sfdisk -l -uS $1 2>/dev/null | awk '
           BEGIN {
             i = 1
           }
           /sectors\/track$/ {
             split ($2, array, ":"); 
             imagefile = array[1];
           }
           /^Units = sectors of/ {
             secsize = $5;
           }
           !/#sectors|sectors\/track$|^$|^Units = sectors of/ && $4 != 0 {
             partoffset = secsize * $2;
             cmd = sprintf ("test -e /mnt/tttt%d", i);
             cmd1 = sprintf ("test -d /mnt/tttt%d", i);
             if (system (cmd) != 0)
             {
               cmd = sprintf ("mkdir /mnt/tttt%d 2>/dev/null", i);
               if (system (cmd) != 0)
               {
                 printf ("Error: Could not create the director /mnt/tttt%d.Please try with root privilege.\n", i);
                 exit;
               }
             }
             else if (system (cmd) != 0)
             {
               printf ("Error: /mnt/tttt%d is not a directory.\n", i);
               exit;
             }
             cmd = sprintf ("mount -o loop,offset=%d %s /mnt/tttt%d", partoffset, imagefile, i); 
             if (system (cmd) != 0)
             {
               exit;
             }
             printf ("Mounting: %s ---> /mnt/tttt%d\n", $1, i);
             i++;
           }'

  To run this script:
  root@ubuntu:~# mountImageFile.sh <image file>

  Run this script with root privilege.

Note: This script will not work for large partitions because of the limitation in sfdisk.
Reference: http://lists.samba.org/archive/linux/2005-April/013444.html & manpages awk and sfdisk

Monday, March 8, 2010

How to create self-Extracting script

It involves 3 steps,
  1. Create Payload
  2. Create Installer script
  3. Packaging
Create Payload:
This is a tar ball  in which all the installable binaries, libraries, script files, configuration files, etc will be placed in the same file hierarchy of the target board considering the base directory of the tar ball is the installation directory on the target board.

periask@ubuntu:~$ mkdir -vp packaging/Payload
mkdir: created directory `packaging
mkdir: created directory `packaging/Payload'
periask@ubuntu:~$ cd packaging/Payload
periask@ubuntu:~/packaging/Payload$ cp --preserve=mode -rl <installables> .
periask@ubuntu:~/packaging/Payload$ tar zcf ../Payload.tar.gz .
periask@ubuntu:~/packaging/Payload$ cd ..
periask@ubuntu:~/packaging$

Create Installer Script:
Copy the below content and create "installer" file in "packaging" directory.

#!/bin/bash

# Get the starting point of the tar ball
SKIP=`awk '/^__ARCHIVE__/ { print NR + 1; exit 0; }' $0`

# Do pre-installation steps here.

# Extracting the tar ball Which is appended to this file
tail -n "+$SKIP" $0 >/dev/null 2>&1
if [ $? -eq 0 ]; then
    tail -n +$SKIP $0 | gunzip -c | tar -C / -xvf -
else
    tail +$SKIP $0 | gunzip -c | tar -C / -xvf - 
fi

# Do post-installation steps here.

exit 0

__ARCHIVE__

Note: There should not be any space  after "__ARCHIVE__" and should be a new line after "__ARCHIVE__".

Packaging:
Concatenate the file "installer" and "Payload.tar.gz" and create the package file.

periask@ubuntu:~/packaging$ cat installer Payload.tar.gz > Package-Version.sh
periask@ubuntu:~/packaging$ chmod +x Package-Version.sh

Installer for your package "Package-Version.sh" is ready.

Source: Linux Journal