My requirement is to split this file based on the date in 5th column. The condition is based on this date and to be splitted by month. So, the number of files would be 12 (a file for each month).
Please help me to write a Unix script to split several files.
Welcome to the forums. The following AWK one-liner will do what you ask. One file per month based on the date in the fifth pipe-delimited column. The filename will be in the form YYYYMM:
awk -F\| '{print > substr($5,1,6)}' file
Should you prefer the files to be named with just the month, MM:
awk -F\| '{print > substr($5,5,2)}' file
Regards,
Alister
---------- Post updated at 11:13 AM ---------- Previous update was at 10:55 AM ----------
A shell version which generates YYYYMM filenames:
#!/bin/sh
file=$1
IFS=\|
while read -r line; do
set -- $line
echo "$line" >> ${5%??}
done < "$file"