file descriptor KSH

Hello,

How can i use file descriptor in a script to read 2 files at the same time and extract line 200 from file 1 and line 500 from file 2.

Thanks.

I don't think we have file descriptors in shell sciprt like we have in perl, c etc.
You can use this to get your requirement done

awk 'NR==200{print}NR>FNR&&FNR==500{print} file1 file2

Note : This logic is specific for 2 files only

regards,
Ahamed

actually create fd is unnecessary but maybe it can be like below that you want :wink:

#!/bin/ksh
>extract1 ;exec 3<file1 ;i=200
while :;do
if [[ $i -ne 0 ]] ; then
 read -r line <&3 ; echo $linecount $line>>extract1 ; ((i--))
else
 for (( i=1 ; i<=500 ; i++ )) ; do
  read -r line < file2 ; echo $linecount $line>>extract1
  [[ $i -eq 50 ]] && exec 3<&- && more extract1 && exit 0; done
fi
done

regards
ygemici

can you check the syntax of your reply i am missing "`"

You want the 200th line or first 200 lines?

regards,
Ahamed

I used the below you provided:
<Code>
awk 'NR==200{print}' fix_UMR_500K.txt | awk '{print $2}'
</code>
is ther any way to substitute NR==200 with NR==$i
It doesnt recognise $i....

Try this

awk -v i=$i 'NR==i{print}' fix_UMR_500K.txt | awk '{print $2}'

regards,
Ahamed