0

我有一些行具有相同的结构,例如

1000    AS34_59329    RICwdsRSYHSD11-2-IPAAPEK-93     /ifshk5/BC_IP/PROJECT/T1
1073/T11073_RICekkR/Fq/AS34_59329/111220_I631_FCC0E5EACXX_L4_RICwdsRSYHSD11-2-IP
AAPEK-93_1.fq.gz        /ifshk5/BC_IP/PROJECT/T11073/T11073_RICekkR/Fq/AS34_5932
9/111220_I631_FCC0E5EACXX_L4_RICwdsRSYHSD11-2-IPAAPEK-93_2.fq.gz        /ifshk5/
BC_IP/PROJECT/T11073/T11073_RICekkR/Fq/AS34_59329/clean_111220_I631_FCC0E5EACXX_
L4_RICwdsRSYHSD11-2-IPAAPEK-93_1.fq.gz.total.info       11.824  0.981393
43.8283 95.7401 OK

我想得到粗体部分来检查是否/home/jesse/有这个文件夹,如果没有创建 mkdir/home/jesse/AS34_59329

我使用此代码

  ! /bin/bash
  myPath="/home/jesse/"
  while read myline
  do
     dirname= echo "$myline" | awk -F ' ' '{print $2}'
     echo $dirname
     myPath= $myPath$dirname
     echo $myPath
     mkdir -p "$myPath"

  done < T11073_all_3254.fq.list

但它不能 mkdir 并显示路径名,它显示

 -bash: /home/jesse/: is a directory
 /home/jesse/
 AS39_59324
4

2 回答 2

1

read可以将每个字段读入一个单独的变量,并且mkdir -p仅当它不存在时才会创建一个目录:

path="/home/jesse"
while read _ dir _ 
do 
    mkdir -p "$path/$dir"
done < T11073_all_3254.fq.list
于 2013-02-05T02:11:43.027 回答
0

for将遍历每个空格分隔的标记。试试这个。

#!/usr/bin/env bash
# Invoke with first arg as file containing the lines
#     foo.sh <input_filename>

for i in `cat $1 | cut -d " " -f2`
do 
    if [ -d /home/jesse/$i ]
    then
        echo "Directory /home/jesse/$i exists"
    else
        mkdir /home/jesse/$i;
        echo "Directory /home/jesse/$i created"
    fi
done
于 2013-02-05T02:06:13.470 回答