我在每一行都有一个长字符串,如
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确定
此行包含三个文件位置(粗体)。我需要将这些文件scp到另一个位置,例如/ sample。
如何在每行中使用shell来scp文件?
while read myline
do
echo "LINE:"$myline
scp .......
done < datafile.list
答案 0 :(得分:1)
如果这些是第4,5和6列,您可以执行以下操作:
while read _ _ _ file1 file2 file3 _
do
scp "$file1" "$file2" "$file3" "user@host:path"
done < datafile.list
答案 1 :(得分: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
答案 2 :(得分: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
答案 3 :(得分:0)
如果您的目标是捕获文件名,记录中的单词数量是可变的,并且文件名不理解空格(如您的示例中所示),您可以尝试这样做:
while read -rd ' ' word || [ "$word" ] ; do
if [ "$word" != "${word#\/}" ] ; then
echo '$word is the name of a file'
fi
done < datafile.list