$ j=0
$ while read line
> do
> if [ $j -eq 0 ]; then
> echo "hi this is the first line"
> j=1
> else
> echo $line
> fi
> done < input_File
hi this is the first line
04;AAA;09;DDD;601020304;AAAA;1;OPTA1;OPTA2;;;
04;BBB;09;BBB;601020304;BBBB;0;OPTB1;OPTB2;OPTB3;OPTB4;OPTB5;
04;CCC;09;DDD;601020304;CCCC;1;;;;;
while read line
do
fields=$(IFS=\;; set -- $line ; echo $#)
a=( $(IFS=\; ; set -- $line ; echo $@ ) )
Status=${a[6]}
if [ $(($fields+1)) -ne 12 ]
then
echo "Incorrect number of fields"
elif [ "$Status" -eq 1 ]
then
echo -n "${a[1]} "
echo "${a[3]}"
fi
done < infile.txt
Try to work from here c=0
while read line
do
if [ $c -eq 0 ];then
let c=1
else
IFS=\;; set -- $line
if [ $# -ne 12 ]; then
echo "Incorrect number of fields"
else
if [ $7 -eq 1 ];then
echo Old is $2 and New is $4 # do whatever you want here
fi
fi
fi
done < file
while read line
do
fields=$(IFS=\;; set -- $line ; echo $#)
echo "Fields are $fields"
a=$(IFS=\; ; set -- $line ; echo $@)
Status=${a[6]}
echo "Status is $Status"
if [ $(($fields+1)) -ne 12 ]
then
echo "Incorrect number of fields"
elif [ "$Status" -eq 1 ]
then
echo -n "${a[1]} "
echo "${a[3]}"
fi
done < $file
my output is,
Fields are 4
Status is
Incorrect number of fields
Fields are 11
Status is
Fields are 12
Status is
Incorrect number of fields
Fields are 11
Status is
I am not able to print the values of array and status variable?
Could you please help me out. Thanks in advance.
Hello guys,
I want to write a ksh script.
I am reading 1st line and now want to read from 2nd line onwards to get details.
Here is my code,
for file in "$INPUT_FILE_FOLDER/"AA_BB_CC*.CSV
do
echo ${file##*/}
TYPE=`echo ${file##*/} | cut -d "_" -f 4`
echo "Type is $TYPE"
line=`head -1 $file`
#echo "Line is : $line"
nrfields=$(IFS=\;; set -- $line; echo $#)
if [ $nrfields -ne 4 ]; then
echo "Incorrect HEADER record fields"
else
Date=`echo $line | cut -d ";" -f 2`
echo "Date is : $Date"
FileType=`echo $line | cut -d ";" -f 4`
echo "File Type is $FileType"
fi
if [ $TYPE == $FileType ]; then
echo "Header record is correct"
// TO DO : read from 2nd line onwards
// check 7th field of line
// if its "1" then get 2nd and 4th filed values in array / variables
// insert array value and Date value into DB table
Could you please help me with respect to this only. As I am totally confused.
for file in "$INPUT_FILE_FOLDER/"AA_BB_CC*.CSV
do
{ IFS=\; read x date x filetype x
if [ -z "$filetype" ]; then
echo "Incorrect HEADER record fields"
exit 1
fi
echo "Date is : $date"
echo "File Type is $filetype"
while IFS=\; read x var2 x var4 x x var7 x
do
if [ $var7 -eq 1 ]; then
echo insertintable $var2 $var4
fi
done
} < "$file"
done
output:
Date is : 20100913115432
File Type is NO
insertintable AAA DDD
insertintable CCC DDD
I need to check the Field value is 12 or not.
IF field value is 12, then only want to check the 7th field else parse next line
if both are getting (fields = 12 and status = 1) then
get the values of 2nd and 4th field.