script to create a file
I am trying to create a file from an existing file or a file list and I am grep'ing an item out of that file to get the records to populate that new file. I have determined if the files are compressed and whether the file is a list of file names or if it is a single file.
The issue that I am having is constructing the loop around the correct items so that my file is created by grabbing each item out of the file/files. CL Syntax: file_create.sh input_file(File_List) item(item_list) Any help you can provide is greatly appreciated. Code:
#!/bin/ksh |
Code:
#----------# Code:
$display $inv_file | grep $btn >> invoice_output |
Quote:
You would also only $display the last one of the file list due to overwriting $inv_file. Either use an array to save all files and $display them at the end. Or $display them right within the for loop of the file list. Not touching on the item_list cause i just dont get it. |
I am trying to account for a couple scenarios. First scenario, an input file ($1) that contains a list of files and a file ($2) that contains a list of items. The second scenario, is a single file with one or more records containing an item from $2. $2 can be a single item (ABC123) or a file containing many items in a list form. $1 can be a single compressed file or a list of compressed/uncompressed files. $2 is never compressed.
I know that my issue is related to my looping constructs. The reason I know this is because every single command works when I execute it on the CLI. The issue as you guys have noted is that the commands are only being executed on the last inv_file and item. BTW - $btn shoul dhave been $item. Sorry for the confusion. |
Code:
while |
michaelk,
Yes, I am grabbing the header record from the source file in the list of files/file ($1) and pushing it into the invoice_output file. Then I need to loop through the Code:
$display $inv_file | grep $item >> invoice_output |
Worst case scenario from your description I think...
Code:
source file To compare the $2 to the temporary file look at the grep -f option. |
Moderator response
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
|
Well I am glad someone can follow this because I am very confused???
I think it would help if you would provide an idea of what a file might look like inside and also the item list in file2? Also, would you please explain what a 'file list' is? Should this mean there are multiple parameters on the command line (ie more than 2)? |
Here we go...
A file ($1) is an invoice file compressed/uncompressed. There is a header record, detail records, summary records, and a trailer record. A file List ($1) is a list of invoice files (see above for definition) that may or may not be compressed. Since this script will be executed in the home dir where all of the files reside file path unnecessary. An $item is a serial number that exists in both the detail record and the summary record. If I grep out abc123 from a source file I could get multiple detail records, but only a single summary record. I want both record types. The concept: I want to be able to create an invoice file from a production source file based on an invoice file or list of invoice files. I also would like to use a single item or a list of items as the criteria for the detail and summary records. The lists are one item per line. Both of them. |
Cool, thanks for the details :)
So if I understand correctly, the process would be: 1. Confirm you received 2 arguments (currently not done) 2. Figure out is $1 is compressed or not ... it would seem here we make an assumption on what type of compression or you can guarantee always the same type? 3. Based on the first line of the file will tell you if you are looking at a single file or one with a list (currently not done). I am also assuming the first line will tell us this 4. Using info from 3 above, we either loop over files or execute the necessary commands, including $2, to get the details Does this sound about right? If so, some will need answers from you to proceed :) |
From the first post it appears that "ABC*\.txt*" defines an invoice file versus a file list.
It is unclear if the file list also has a header record etc. I assume that you are creating a summary or trailer record by counting the lines in the file i.e. wc -l invoice_output | nawk '(print $1)' | read count echo "T|$count">>invoice_output I think you need to process the invoice file separately from the file list. Using the eval command you can iterate through the file list whether compressed or uncompressed. The ifs or pseudo code but the loop is real but untested. Code:
# if $1 is a file list |
All times are GMT -5. The time now is 03:10 AM. |