#!/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
Sunday, November 1, 2009
Posted by venu k
7 comments | 11:56 AM
Subscribe to:
Post Comments (Atom)
your blog is rocking man. I practiced many scripts form your blog. It's really helpful.
ReplyDeleteThank for sharing your knowledge.
K Pallavi
There's no need to repeat the inner loop for every line:
ReplyDeleteLINE=
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"
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
ReplyDeletethank you in advance
cadinho
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 .
ReplyDeleteCan anyone clear my concept behind loops.. Taking variables.. I am beginner.. Reply asap
ReplyDeleteIt’s very excellent information
ReplyDeletenice post thank you
ReplyDeleteappvn apk
tutuapp apk ios