Rishabh
Rishabh

Reputation: 67

Want to append records in two file using shell script

My first input file contains records name abc.txt:

[email protected]

[email protected]

[email protected]

[email protected]

My second file contains record name details.txt:

123456^atulsample^1203320

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

[email protected]^123456^atulsample^1203320

[email protected]^123456^atulsample^1203320

[email protected]^123456^atulsample^1203320

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

Kindly help as I don't have much knowledge in shell scripting.

Upvotes: 1

Views: 56

Answers (1)

Mustafa DOGRU
Mustafa DOGRU

Reputation: 4112

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}/"

Upvotes: 1

Related Questions