0

I have one set of files with naming convention bond_7.LEU.CA.1.dat bond_10.VAL.CB.1.dat..... and have other set of files starting with the string distance rather than bond with the same extension i.e.,distance_7.LEU.CA.1.dat .... and i am trying to merge corresponding or subsequent lines of files using paste command in shell scripting

I am intending to do paste bond_7.LEU.CA.1.dat distance_7.LEU.CA.1.dat > ../raj/angle_dist_7.LEU.CA.dat

I have tried to use for loop and stuck with replacing the string of the file name to access the appropriate file.

Thanks in advance,

Any help will be appreciated.

1 Answer 1

1
#!/bin/bash
for FILE in bond* 
do
    paste "$FILE" "${FILE/bond/distance}" > "../raj/${FILE/bond/angle_dist}"
done

Is that it?

ps. Such substitutions don't work in pure sh. You should to use bash or ksh or zsh or smth like that.

pps. To use it with sh replace "${FILE/bond/distance}" with

`echo $FILE | sed 's/bond/distance/'`
Sign up to request clarification or add additional context in comments.

3 Comments

+1: note that although ${FILE/bond/distance} is non standard, you can use the standard distance${FILE#bond} to achieve the same thing.
@WilliamPursell: it is standard in bash, see the BASG, search for ${string/substring/replacement}.
standard in bash is an oxymoron. It works in bash, and some other shells, but it is not standard bourne shell syntax.

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.