Monday, 15 February 2010

bash - using data one by one of two different variable to replace words using sed -



bash - using data one by one of two different variable to replace words using sed -

i have 2 files list1.txt , list2.txt

list1.txt have name b c d list2.txt have names 1 2 3 4

i have stored 2 lists info in 2 variables say

var1=$(<list1.txt) var2=$(<list2.txt)

i have file contain x y names in want create files replacing 2 x y 1 info list1 , 1 list2 have create 4 files file1 have 1 file2 have b 2 , on...

please help me out have create several files info stored in 2 list files.

one way utilize paste bring together corresponding lines of list1.txt , list2.txt , utilize split split result multiple output files, 1 line per file.

split -a 1 -d -l 1 <(paste -d" " list1.txt list2.txt) out

the other way utilize arrays:

arr1=( $(<list1.txt) ) arr2=( $(<list2.txt) ) (( i=0; i<${#arr1[@]}; i++ )) echo "${arr1[$i]} ${arr2[$i]}" > "out$i" done

bash shell sed

No comments:

Post a Comment