The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



Thread: Help in unix
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 05-16-2008
era era is online now
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,605
set is not a useful sh command in this context, and you need to avoid having spaces on either side of the equals signs. Also take care to put spaces where you do need them.

Code:
#! /bin/sh

i=0
count=$(wc -l < file2.txt)
while [ $i -le $count ]
do
   i=`expr $i + 3`
   head -n $i file2.txt >> file1.txt
done
As such, simply head -n 3 file2.txt >>file1.txt should do what you want. Or maybe I misunderstand your problem description. Either way, your loop will read from the beginning of file2.txt on each iteration, which doesn't seem useful.

Last edited by era; 05-16-2008 at 01:48 PM. Reason: Note that head reads first n lines every time
Reply With Quote