1

i have a long string in each line like

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

This line contains three file locations (in bold). I need to scp those files to another location like /sample.

How can I use shell to scp files in each line?

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

  done < datafile.list 
1
  • I think you might want to check out awk. Commented Feb 1, 2013 at 8:14

4 Answers 4

1

Using 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
Sign up to request clarification or add additional context in comments.

1 Comment

+1 Nice solution. It will try to collect as many files as possible into one scp call.
1

If these are columns 4, 5 and 6, you can do:

while read _ _ _ file1 file2 file3 _ 
do  
    scp "$file1" "$file2" "$file3" "user@host:path"
done < datafile.list 

1 Comment

thanks, but i don't know you answer. each line contains 3 file locations and other information, i need scp all lines files.
0

You can check if the part of your string is a file with -f and afterwards do your 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

2 Comments

thanks, i just start learn shell. the i in echo str, i means? it can means any part in str?
The echo is completely useless. Fixed. Also note that this will fail when the file names contain spaces.
0

If your goal is to catch the filenames, that the number of words in a record is variable, and that the filenames don't comprehend spaces (as in your example), you could try this :

while read -rd ' ' word || [ "$word" ] ; do
    if [ "$word" != "${word#\/}" ] ; then
        echo '$word is the name of a file'
    fi
done < datafile.list

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.