[Bash] Insert blanks for missing fields and reorder
I am trying to process inventory addition files for insertion into a MySQL database. The format convention is book UIEE. If the field for the add file has no data, the field is NOT included in the upload file, so I need to add a blank/empty for any missing fields. The I need to create a csv or tsv file for the actual insertion. I have the main conversion part down, but I am having issues with inserting the blanks. I need to check if it is present first.
Here is the code I have so far:
Here is a sample of the file I am processing (routinely contains 1200+ lines and yes the last line is empty:
Any help, even it is to point into a better direction is greatly appreciated. I am not familiar with awk, but I do know sed.
---------- Post updated 08-17-09 at 05:56 PM ---------- Previous update was 08-16-09 at 10:34 PM ----------
Here is another failed attempt, but perhaps it will give a better idea of what I am trying to accomplish:
Again, any help, even if to only point out errors, might help me get past this sticking point.
Thanks in advance!
Last edited by LoveSquid; 08-17-2009 at 05:36 PM..
Hi Fellows,
I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem:
I have csv files in the following pipe-delimited format:
Column1|Column2|Column3|Column4|NEWLINE
Address Type|some descriptive... (4 Replies)
Hi Friends,
I have come across some files where some of the columns don not have data.
Key, Data1,Data2,Data3,Data4,Data5
A,5,6,,10,,
A,3,4,,3,,
B,1,,4,5,,
B,2,,3,4,,
If we see the above data on Data5 column do not have any row got filled. So remove only that column(Here Data5) and... (4 Replies)
Hi all,
I have two (2) sets of files that are based on some snapshots of database that I want to merge and insert any missing sequential number.
Below are example representation of these files:
file1:
DATE TIME COL1 COL2 COL3 COL4 ID
01/10/2013 0800 100 ... (3 Replies)
Hi,
I have a csv file with content like:
1,0,100
1,1,150
2,0,200
2,1,250
3,0,300
3,1,350
I want an output such that all numbers in 3rd col where 2nd col is "0" come in the same col in the output. The same goes for numbers where 2nd col is "1".
1 100 150
2 200 250
3 300 350
Tnx... (2 Replies)
Hi, please help with this, I need to insert missing values into a matrix for a regression analysis.
I have made up an example. The first three columns are variables with levels and the next 3 are values, the 4th column missing values should be replaced by 0s, and 5th and 6th column missing... (3 Replies)
Hello experts!
I have 2 files.
file1 is a list file containing uniquely names. e.g.:
name1 number number
name2 number number
name5 number number
name10 number number
...
file2 is a data file arbitrary containing the names of file1 in paragraphs separated by "10" e.g.
name4 ... (3 Replies)
I have 2 for loop in my program , first one will list files based on timestamp and second one list the files based on type(RPT / SUB_RPT).Here is my code:
#!/bin/ksh
STG_DIR=/home/stg
for pattern in `find $STG_DIR -type f -name 'IBC*csv' | awk -F'' '{print $(NF-1)}' | sort -u`
do
echo... (2 Replies)
Using the file below, which will always have the first indicated by the digit after the -
and last id in it, indicated by the digit after the -, I am trying to use awk
to print the missing line or lines in file following the pattern of the previous line.
For example, in the file below the next... (4 Replies)
can anyone help me!!!! How to I parse the CSV file
file name : abc.csv (csv file) The above file containing data like
abv,sfs,,hju,',',jkk wff,fst,,rgr,',',rgr ere,edf,erg,',',rgr,rgr I have a requirement like i have to extract different field and assign them into different... (4 Replies)