Rishabh Rishabh - 2 months ago 6
Bash Question

want to append records in two file using shell script

My first input file contains records name abc.txt:

abc@gmail.com

bscd@yahoo.co.in

abcd.21@gmail.com

1234@hotmail.com

My second file contains record name details.txt:

123456^atulsample^1203320

I want my final file having output to be Final.txt:

abc@gmail.com^123456^atulsample^1203320

bscd@yahoo.co.in^123456^atulsample^1203320

abcd.21@gmail.com^123456^atulsample^1203320

I have uses sed command but I am not getting my required output

Kindly help as i dont have much knowledge in shell scripting

Answer

try something like this;

#!/bin/bash
while read -r line
do
    detail="$line"
    sed '/^[ \t]*$/d' abc.txt | sed "s/$/^${detail}/" >> Final.txt
done < "details.txt"

this is to delete blank lines;

 sed '/^[ \t]*$/d' abc.txt

this is to append from details.txt

sed "s/$/^${detail}/"