#!/usr/bin/env bash
# 用法说明
if [ $# -lt 1 ]; then
echo "用法: $0 <input.gff3> [output.gff3]"
exit 1
fi
infile="$1"
# 如果指定了第二个参数就用作输出文件名,否则默认写到 SgChr_lines.gff3
if [ $# -ge 2 ]; then
outfile="$2"
else
outfile="SgChr_lines.gff3"
fi
# 如果是 gzip 压缩文件,使用 zcat;否则用 cat
if [[ "$infile" == *.gz ]]; then
reader="zcat"
else
reader="cat"
fi
# 提取第一列中包含 SgChr 的行
# 跳过以 # 开头的注释行(可选)
$reader "$infile" \
| awk -F $'\t' '$1 ~ /SgChr/ && $0 !~ /^#/ { print }' \
> "$outfile"
echo "提取完成,结果已写入:$outfile"