• Welcome to Bashguru

    Linux is one of popular version of UNIX operating System. It is open source as its source code is freely available. It is free to use. Linux was designed considering UNIX compatibility. It's functionality list is quite similar to that of UNIX and become very popular over the last several years. Our Basic motive is to provide latest information about Linux Operating system.

  • Python Programming

    Python is a comparatively simple programming language, compared to c++. Although some of the benefits of c++ are abstracted away in python, they are replaced with an overall easier to learn language with many “intuitive” features. For this reason it is common and recommended by most professionals that people new to programming start with python.

  • Perl Programming

    Perl is an open-source, general-purpose interpreted programming language. Used often for CGI, Perl is also used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications. The Perl languages borrow features from other programming languages including C, shell scripting (sh), AWK, and sed. They provide powerful text processing facilities without the arbitrary data-length limits of many contemporary UNIX command line tools, facilitating easy manipulation of text files.

  • Android

    Android is an operating system based on the Linux kernel, and designed primarily for touch screen mobile devices such as smart phones and tablet computers. Android is a Linux-based software system, and similar to Linux, is free and open source software. This means that other companies can use the Android operating developed by Google and use it in their mobile devices.Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly.

Sunday, November 1, 2009

Posted by venu k
7 comments | 11:56 AM

#!/bin/bash
#
# SCRIPT: bigfile.sh
# PURPOSE: This script is used to create a text file that
# has a specified number of lines that is specified
# on the command line.
#


usage()
{

echo "............USAGE ERROR............"
echo "USAGE: $0 <number_of_lines_to_create>"
}

# Argument Checking

if [ $# -ne 1 ] # Looking for exactly one parameter
then
usage # Usage error was made
exit 1 # Exit on a usage error
fi

# Define files and variables here

LINE_LENGTH=80 # Number of characters per line
OUT_FILE=bigfile.$$ # New file to create
>$OUT_FILE # Initialize to a zero-sized file
TOTAL_LINES=$1 # Total number of lines to create
LINE_COUNT=0 # Character counter
CHAR=X # Character to write to the file

# Beginning of Main

while ((LINE_COUNT < TOTAL_LINES))
do
CHAR_COUNT=0 # Initialize the CHAR_COUNT to zero on every new line

while ((CHAR_COUNT < LINE_LENGTH)) # Each line is fixed length
do
echo -e "$CHAR\c" >> $OUT_FILE # Echo a single character
let CHAR_COUNT++ # Increment the character counter
done

let LINE_COUNT++
echo>>$OUT_FILE # Give a newline character
done

7 comments:

  1. your blog is rocking man. I practiced many scripts form your blog. It's really helpful.
    Thank for sharing your knowledge.

    K Pallavi

    ReplyDelete
  2. There's no need to repeat the inner loop for every line:

    LINE=
    while [ $(( CHAR_COUNT += 1 )) -le $LINE_LENGTH ]
    do
    LINE=$LINE$CHAR
    done

    while [ $(( LINE_COUNT += 1 )) -le $TOTAL_LINES ]
    do
    echo "$LINE"
    done > "$OUT_FILE"



    ReplyDelete
  3. i have a problem with updating one of the fields in my file....i want the field to be updated everyday by adding one when the employee is absent

    thank you in advance
    cadinho

    ReplyDelete
  4. This article great helped him and tell us how to create a shell script file and how to save data thanks for share it biosketch format .

    ReplyDelete
  5. Can anyone clear my concept behind loops.. Taking variables.. I am beginner.. Reply asap

    ReplyDelete
  6. It’s very excellent information

    ReplyDelete