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 -->
  #2 (permalink)  
Old 06-26-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
It depends on where you want to add the filename in the output file, but look at this:
Code:
#!/bin/ksh

awk -F/ '{print $1,$2,$3}' os_listing.out | while read filesize dirname filename; do
        mkdir $dirname
        cd $dirname
        echo $filename $filesize > $filename
        count=$(($filesize-${#filename}))
        dd if=/tmp/inputfile of=$filename bs=1 count=$count seek=${#filename}
        cd ..
done
This code adds the filename to the beginning of the file and then appends (count-length_of_filename) characters from the input file.