Twelve Methods to Parse a File Line by Line — Part 3

Here we are continues the magic. You can find the part 1 & 2 here ….
Twelve Methods to Parse a File Line by Line — Part 1
Twelve Methods to Parse a File Line by Line — Part 2

Method 7:

cat $FILENAME | while LINE=$(line)
function while_LINE_line_cmdsub2
{
cat $FILENAME | while LINE=$(line)
do
echo "$LINE"
done
}

Method 8:

while LINE=$(line) from the Bottom
function while_LINE_line_bottom_cmdsub2
{
while LINE=$(line)
do
echo "$LINE"
done < $FILENAME
}

Method 9:

while read LINE Using File Descriptors
function while_read_LINE_FD
{
exec 3<&0
exec 0< $FILENAME
while read LINE
do
echo “$LINE”
:
done
exec 0<&3
}

njoy the simplicity…….
© Mastering Unix Shell Scripting

Advertisements

Twelve Methods to Parse a File Line by Line — Part 2

Here we are continues the magic. You can find the part 1 here ….
Twelve Methods to Parse a File Line by Line — Part 1

 

Method 4:

cat $FILENAME | while LINE=`line`
function cat_while_LINE_line
{
cat $FILENAME | while LINE=`line`
do
echo "$LINE"
done
}


Method 5:

cat $FILENAME | while line LINE
function while_line_LINE
{
cat $FILENAME | while line LINE
do
echo "$LINE"
done
}


Method 6:

while LINE=`line` from the Bottom
function while_LINE_line_bottom
{
while LINE=`line`
do
echo "$LINE"
done < $FILENAME
}

 

njoy the simplicity…..

© Mastering Unix Shell Scripting

Twelve Methods to Parse a File Line by Line — Part 1

Hi Guys,

Today, In this series we learn 12 method to parse the file in Linux/Unix.

Method 1:

cat $FILENAME | while read LINE
function while_read_LINE
{
cat $FILENAME | while read LINE
do
echo "$LINE"
done
}

Method 2:

while read $FILENAME from Bottom ------------------ BEST_ONE
function while_read_LINE_bottom
{
while read LINE
do
echo "$LINE"
done < $FILENAME
}

Method 3:

while_line_LINE_Bottom
function while_line_LINE_bottom
{
while line LINE
do
echo $LINE
done < $FILENAME
}

njoy the simplicity…….

© Mastering Unix Shell Scripting

The Unix Time Command : tips & tricks

If you have a program ./prog.e then in the bash/ksh shell you can type this command and the output on the screen details how long the code took to run:
     
$ time ./prog.e
real   24m10.951s user    6m2.390s sys     0m15.705s



Real time – Elapsed time from beginning to end of program (or wall clock time).The real time is the total  time of execution.
CPU time – Divided into User time and System time.
User time – time used by the program itself and any library subroutines it calls.The user time is the time spent processing at the user/application process level.
System time – time used by the system calls invoked by the program (directly or indirectly).The sys time is the time spent by the system at the system/kernel level.

If the wall clock time is consistently much longer than the total of the system and user time, then the fetching of data to and from hard drives may be taking a good deal of time. In parallel codes, the code may be spending a good deal of time waiting on communication between processors.

By this command you can check your script performance.

happy scripting 🙂

 
 

njoy the simplicity…….
©Victimizeit

Script/Code Header

Hi Guys, I am sharing a Script Header or we can say a Code Header
which we can use in our code to provide more proper description of the code.


Please find the link.  download
 
 

njoy the simplicity…….
©Victimizeit