I am facing a strange error while splitting a '|' delimited file 'file1' based on column '3'. (File is 40 columns wide).
I wish to create as many files 'file_n' from the file 'file1' as distinct values of the column '3'; in 'file1'
eg: file1:
qwe|qweqw|123|fg
fdgg|1ffgfdsg|456|df
qw|we|1|df
output expected:
file_123:
qwe|qweqw|123|fg
file_456:
fdgg|ffgfdsg|456|df
file_1:
qw|we|1|df
Code:
$CUT -d "|" -f3 ${SRC_FILE}|sort|uniq> ${VID_FILE}
for i in `cat ${VID_FILE}`;
do SPLIT_FILE=${file1/1/`echo ${i}`}
echo $SPLIT_FILE
DEST_DIR=${FTP_DIR}/RTM/Outbound
What is happening is for all values of colmun '3' which are '3' charecters wide I am getting correct output but for column value '1' for some reason the output file 'file_1' contains the records with other column values too.
but I am not at all conversant in 'awk' , infact this is my first attempt at shell.
Anyways the problem too is generic i.e. column '3' in input file 'file1' can take say 'n' distinct values, that is why
I have captured the unique fields from column '3' in a 'VID_FILE' .
Now for every value in VID_FILE I am trying to fetch all the records from the 'file1'.For some reason for a particular value '1' (in this example) in 'VID_FILE' which is 1 character less wider than the others is causing the wrong data to get inserted in the file.
I am sure for other records where column '3' might be 4 charcters long I might land up into trouble.
I have a '|' delimited flat file with 40 columns say 'input_file'.
I need to split this file 'input_file' into number of files (output file_name = input_file_value_of col_33) based on the column no '33' in 'input_file'.
i.e. for 'n' distinct values of column '33' in 'input_file' we will have 'n' output files each having names 'input_file_n1', 'input_file_n2'....'input_file_n'
where n1, n2, n3 are values of column '33' in 'input_file'.
The script which I wrote works fine only when n1,n2, n3 are all of equal width.
I need help to split the above file for distinct values of column '33'