The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 08-30-2008
Peetrus Peetrus is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 2
Weird sed behaviour in script

I've written a small script to replace certain words in all the the files in a directory.

Code:
#!/bin/sh

#Get list of files to be edited

file_list=`ls -p`

for i in $file_list
do
echo "Processing $i"

alteredi=`echo "$i" | sed -e 's/\//d/'`

if [ $i = $alteredi ]
then
	if [ $i != "maketest" ]
	then
	#actual altering
	
	cat $i | sed -e "s/login\//login.tst\//" > $i
	cat $i | sed -e "s/cyberkd\//cyberkd.tst\//" > $i
	cat $i | sed -e "s/\/db_connect.inc.php/\/testdb_connect.inc.php/" > $i
	echo "  $i has been altered"
	else
	echo "  Not altering myself"
	fi

else
echo "  Not altering directories"
fi

done
Now, when I run this script as a normal user, only the first 4kB of the file is processed. So all files larger than 4kB are cut in half. The remaining bytes are just left out of the new file. When I ran the script as root, 8kB were processed. Is there a way to process the entire files?

When I cat a large text file the entire file gets printed on my screen.

Thanks in advance.