Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.

Join On A String

Thread Tools Search this Thread
# 1  
Join On A String

Is is possible to join on unsorted files by a string? Don't want to sort because there is other text that is already in a good format.

File1 has this text string:

File2 has this text string:

I want to replace or join ABCD-123 in file 2 with ABCD-123 FGH in file 1.
Thank you.
# 3  
Desired output would be for file2: ABCD-123 FGH. There are multiple ones though. So it would be:
ABCD-123 FGH and BCDE-345 JKL etc.
Not using sed because each instance is unique. Not sure if I'm being clear.

---------- Post updated at 03:24 PM ---------- Previous update was at 03:17 PM ----------

Just looked at my response, let me re-phrase it.
Desired output would be
But these would appear in different places in the text file. Hope this is clearer and I do appreciate the help.
# 7  
Maybe it should be:
awk 'NR==FNR { A[$1]=$1; next } $1 in A' file2 file1

Sorry, just read the post and thought "this is the error"; just did not test it yet.
(I HATE variable spacing fonts! Had to edit this post too many times just to align the arrow with the error)

Moderator's Comments:
Mod Comment Nope. The code is fine.

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
awk - How to join the string with values
Hi, I'm a beginner in awk script. I've been trying to figure how to concatenate two string in input file using awk after the value is calculated. I'm trying to get this format Apple 5.2(10) Orange 4.4(8) Watermelon 3.10(30) Berries 10.2(20) The input file with the format fruit...... UNIX for Dummies Questions & Answers
UNIX for Dummies Questions & Answers
How to use the the join command to join multiple files by a common column
Hi, I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column). I want to write a script to join the files by the first common column so that in the...... UNIX for Dummies Questions & Answers
UNIX for Dummies Questions & Answers
Join lines with the same start string
I have the text like: DN11-001 Thats the first line which needs to be DN11-001 joined with the second line and also to DN11-001 the third line as they all begin with the same DN11-001 document number. DN11-002 The number of lines differ DN11-002 among the documents. DN11-005 It can also be...... Shell Programming and Scripting
Shell Programming and Scripting
Join 2 files with multiple columns: awk/grep/join?
Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7...... UNIX for Dummies Questions & Answers
UNIX for Dummies Questions & Answers
Use of uninitialized value in join or string at
When try to execute the following script, its throwing this error: " Use of uninitialized value in join or string at line 17. " The script is : 1 #!/usr/bin/perl 2 3 use strict; 4 5 my @a = ( 1...10 ); 6 7 print " Original array : @a...... Shell Programming and Scripting
Shell Programming and Scripting

Featured Tech Videos