Generating files of specific size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generating files of specific size
# 1  
Old 06-26-2006
Generating files of specific size

I've been working on getting a script to take size, dir name and file name variables from an input file and creating the same dir structure along with the file of specific size.

An example of the input file:

size/dirname/filename
Code:
2100/JAN_06/12345ABC.TCC
2354/FEB_06/24564XYZ.NOS
11240/MAR_06/1212ABAB.NCC

I am able to get results with the following code:
Code:
#!/bin/sh

set filesize=$1
set dirname=$2
set filename=$3

awk -F/ '{print $1,$2,$3}' os_listing.out | \
while read filesize dirname filename
do
        mkdir $dirname
        cd $dirname
        dd if=test/inputfile of=$filename bs=1 count=$filesize
        cd ..
done

The input file is just a file with random text that equals the size of the largest file this script will create.

What I'm trying to figure out is how to add text of a fixed character length, specifically the file name inside each file when it's created, then have the dd command create the file of specific size.

If I use any of the seek options with the dd command, it will just add onto the count size, which results in larger files.

Please let me know if additional information is needed.

Thank you in advance for any help and support.

Last edited by Yogesh Sawant; 02-26-2010 at 02:07 PM.. Reason: added code tags
# 2  
Old 06-26-2006
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.
# 3  
Old 06-27-2006
That works beautifully. Thank you very much for the quick reply. I truly appreciate the great help. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding lines of specific size in files using sed

i am using sed to detect any lines that are not exactly 21. the following gives me the lines that ARE exactly 21. i want the opposite , i want the two lines that are not size 21 (shown in bold) type a.a 000008050110010201NNN 000008060810010201NNN 21212000008070110010201NNN... (5 Replies)
Discussion started by: boncuk
5 Replies

2. Shell Programming and Scripting

Comparing two files and generating the report

Hi All, What am trying to do is generate the report by compating two files. File A ----------- 111 22222 3333 222 55555 7777 File B ----------- 11A 22222 3333 333 55555 7778 Now the report should be as follows Added: 333 55555 7778 Removed: (6 Replies)
Discussion started by: Prashantckc
6 Replies

3. Shell Programming and Scripting

Randomly selecting sequences and generating specific output files

I have two files containing hundreds of different sequences with the same Identifiers (ID-001, ID-002, etc.,), something like this: Infile1: ID-001 ATGGGAGCGGGGGCGTCTGCCTTGAGGGGAGAGAAGCTAGATACA ID-002 ATGGGAGCGGGGGCGTCTGTTTTGAGGGGAGAGAAGCTAGATACA ID-003... (18 Replies)
Discussion started by: Xterra
18 Replies

4. Shell Programming and Scripting

Generating MD5's of files

On my website I host a lot of files, and when people view the site, currently each time the page loads, I have PHP generating the md5 sums for the files right then and there. It was fine when my site was small, but now that's obviously very inefficient. Now I'd like to start generating MD5 sums... (4 Replies)
Discussion started by: GrdLock
4 Replies

5. Shell Programming and Scripting

Find files of specific size excluding search in a subdirectory

Hi All, I was exploring find command and came across -prune option which would exclude search in a mention subdirectory. My quesry is to search all files more that 100 MB size but exclude search in a subdirectory. I am using below command,but somehow it is not working. Can anybody help me... (6 Replies)
Discussion started by: usha rao
6 Replies

6. Shell Programming and Scripting

Creating large number of files of specific size

Hi I am new to shell scripting.I want to create a batch file which creates a desired number of files with a specific size say 1MB each to consume space.How can i go about it using for loop /any other loop condition using shell script? Thanks (3 Replies)
Discussion started by: swatideswal
3 Replies

7. Shell Programming and Scripting

Generating random number within a specific range (0.5-1.5)

Hello, need a way to generate numbers within 0.5-1.5 range Has to be totally random: 0.6 1.1 0.8 1.5 0.6 and so on.... How to? (10 Replies)
Discussion started by: TehOne
10 Replies

8. Shell Programming and Scripting

Generating files.

I/P file name:- 20092008.txt Check number of entries in i/p file by following command ChkEnt -infl 20092008.txt -opfl 20092008_test.txt >count.txt Dear Friends, Please help me in automating following thing. If output generated (count.txt) is having value more than 1000 i.e.... (8 Replies)
Discussion started by: anushree.a
8 Replies

9. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies

10. Shell Programming and Scripting

bash script working for small size files but not for big size files.

Hi, I have one file stat. Stat file contents are as follows: for example. H50768020040913,00260100,507680,13,0000000643,0000000643,00000,0000 H50769520040808,00260100,507695,13,0000000000,0000000000,00000,0000 H50770620040611,00260100,507706,13,0000000000,0000000000,00000,0000 Now i... (1 Reply)
Discussion started by: davidpreml
1 Replies
Login or Register to Ask a Question