Issue
I have a scenario where i want to initialize the value of variable a
to sed command
at run time
My code :
for i in `cat /d/file1.txt`
do
a=$i
v=`sed $a'p' /d/file2.txt`
echo "$a : $v"
done
This above code give me error : unterminated address regex
Getting at command : sed
Solution
It seems like the user is trying to read 2 files parallelly , if that the case
Lets Assume you have 2 files
File1.txt
ABC
XYZ
PQR
File2.txt
FTY
UIO
ASD
Your code :
# Note : Assuming the 2 set of files have equal number of records
#!/bin/sh
# Get count of record from file
vfile1count="$(grep -vc '^$' /d/file1.txt)"
export vfile1count
for(( i=1; i<=$(vfile1count); $((i+1)) ))
do
f1=$(sed "$i"'p' /d/file1.txt)
f2=$(sed "$i"'p' /d/file2.txt)
echo "File 1 : $f1 ---> File 2 : $f2"
done
Output :
ABC --> FTY
XYZ --> UID
PQR --> ASD
Feel free to edit it you see any error's
Answered By - codeholic24