Question

I have two txt files

the first file structure

text1|text2

the seconde file structure is

text2|text3

Now I want to replace all the text2 of the first file with the text3 of the seconde file , and the condition must be text2 of the first file muchs with the text2 of the seconde file

Example

First File:

sfaxsy|contact@syfax.net
user2|admin@syfax.net

Seconde file:

admin@syfax.net|verified
contact@syfax.net|unverified

Final File :

sfaxsy|unverified
user2|verified

I have over 3k lines

Thanks guys

Was it helpful?

Solution

I'm assuming that you have shell scripting available to you. This script solves it.

#!/bin/sh
for line in `cat file1`; do
    pt1=`echo $line | cut -f 1 -d '|'`
    key=`echo $line | cut -f 2 -d '|'`
    pt2=`grep "${key}" file2 | cut -f 2 -d '|'`
    echo "$pt1|$pt2" >> file3
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top