[SATLUG] Shell scripting challenge

Emon emon at lavabit.com
Tue Apr 7 13:26:20 CDT 2009


Hi again

I made some minor modifications to the script, it now looks like this


*****************************************

#!/bin/bash

printf "Enter absolute file path "

read FILE

lc=$(wc -l $FILE | awk '{print $1}')
((j=lc/5))

for i in 1 2 3 4
	do
	((x=j*i))
	head -$x $FILE | tail -$j >> File_Section_$i
done

((x=x+1))
tail +$x $FILE >> File_Section_5

*****************************************

I have run this script on an file (also named "file") in my home
directory which sixteen lines with the numbers one to sixteen typed at
the beginning of each line; and it works just fine. I am running
"openSUSE 11.1" fully updated.
But when I ran this program on a "RHEL 5.2" machine on the same file, it
produces five files but reported error

**************
tail: cannot open `+13' for reading: No such file or directory
**************

When I checked the output of the 5th file (File_Section_5); it looked
like this

*********************
==> /home/student/file <==
7
8
9
10
11
12
13
14
15
16
*********************

So, have I made any mistake in the script or is there something else
that I over looked???

Emon




More information about the SATLUG mailing list