1

我在每一行都有一个长字符串,比如

1000 AS34_59329 RICwdsRSYHSD11-2-IPAAPEK-93 /ifshk5/BC_IP/PROJECT/T11073/T11073_RICekkR/Fq/AS34_59329/111220_I631_FCC0E5EACXX_L4_RICwdsRSYHSD11-2-IPAAPEK-93_1.fq.gz / ifshk5 / BC_IP / PROJECT / T11073 / T11073_RICekkR / Fq上/ AS34_59329 / 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

此行包含三个文件位置(粗体)。我需要将这些文件 scp 到另一个位置,例如 /sample。

如何使用 shell 对每一行中的文件进行 scp 处理?

 while read myline  
  do  
    echo "LINE:"$myline 
    scp .......

  done < datafile.list 
4

4 回答 4

1

如果这些是第 4、5 和 6 列,您可以执行以下操作:

while read _ _ _ file1 file2 file3 _ 
do  
    scp "$file1" "$file2" "$file3" "user@host:path"
done < datafile.list 
于 2013-02-01T08:15:10.987 回答
1

使用grep

# grep each file name
$ grep -o "/[^ ]*" datafile.list
/ifshk5/BC_IP/PROJECT/T11073/T11073_RICekkR/Fq/AS34_59329/111220_I631_FCC0E5EACXX_L4_RICwdsRSYHSD11-2-IPAAPEK-93_1.fq.gz
/ifshk5/BC_IP/PROJECT/T11073/T11073_RICekkR/Fq/AS34_59329/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

# Pipe files to scp 
$ grep -o "/[^ ]*" datafile.list | xargs -i% scp % host:/sample
于 2013-02-01T08:37:06.867 回答
0

您可以检查您的字符串的一部分是否是一个文件,-f然后执行您的scp.

#!/bin/bash
str="1000 AS34_59329 RICwdsRSYHSD11-2-IPAAPEK-93 /ifshk5/BC_IP/PROJECT/T11073/T11073_RICekkR/Fq/AS34_59329/111220_I631_FCC0E5EACXX_L4_RICwdsRSYHSD11-2-IPAAPEK-93_1.fq.gz /ifshk5/BC_IP/PROJECT/T11073/T11073_RICekkR/Fq/AS34_59329/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"

for i in $str
do
  if [ -f $i ]; then
    echo $i
    # scp here
  fi
done
于 2013-02-01T08:26:56.513 回答
0

如果您的目标是捕获文件名,记录中的单词数是可变的,并且文件名不包含空格(如您的示例中所示),您可以尝试以下操作:

while read -rd ' ' word || [ "$word" ] ; do
    if [ "$word" != "${word#\/}" ] ; then
        echo '$word is the name of a file'
    fi
done < datafile.list
于 2013-02-01T09:18:47.263 回答