Home Man
Search
Today's Posts
Register

This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in the UNIX for Beginners Questions & Answers forum.

Join On A String

Tags
beginners

 

 
Thread Tools Search this Thread
# 1  
Old 10-11-2012
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:
ABCD-123 FGH

File2 has this text string:
ABCD-123

I want to replace or join ABCD-123 in file 2 with ABCD-123 FGH in file 1.
Thank you.
# 2  
Old 10-11-2012
What output would you want for that input?
# 3  
Old 10-11-2012
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
ABCD-123 AAA
ABCD-456 BBB
ABCD-789 CCC
But these would appear in different places in the text file. Hope this is clearer and I do appreciate the help.
# 4  
Old 10-11-2012
Code:
awk 'NR==FNR { A[$1]=1; next } $1 in A' file2 file1

# 5  
Old 10-11-2012
syntax error Corona
# 6  
Old 10-11-2012
Which syntax error?

Use nawk on solaris.
# 7  
Old 10-11-2012
Maybe it should be:
Code:
awk 'NR==FNR { A[$1]=$1; next } $1 in A' file2 file1
                     ^
                  Missing

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:
Join On A String Nope. The code is fine.
 

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk - How to join the string with values KCApple UNIX for Dummies Questions & Answers 2 05-14-2013 01:37 AM
How to use the the join command to join multiple files by a common column evelibertine UNIX for Dummies Questions & Answers 5 07-05-2012 04:15 PM
sed or awk command to replace a string pattern with another string based on position of this string vivek d r Shell Programming and Scripting 10 06-19-2012 09:35 AM
how to join two files using "Join" command with one common field in this problem? mindfreak UNIX for Dummies Questions & Answers 2 04-13-2012 05:55 AM
to extract string from main string and string comparison vivek d r Shell Programming and Scripting 2 11-16-2011 07:17 AM
Join lines with the same start string andrejm Shell Programming and Scripting 10 10-02-2011 02:26 PM
Join 2 files with multiple columns: awk/grep/join? InfoSeeker UNIX for Dummies Questions & Answers 3 12-01-2009 07:45 PM
sql,multiple join,outer join issue robbiezr Programming 0 06-05-2009 11:26 PM
join (pls help on join command) summer_cherry Shell Programming and Scripting 1 12-31-2007 04:19 AM
Use of uninitialized value in join or string at arraydef.pl praveen_b744 Shell Programming and Scripting 5 08-31-2007 10:09 AM


All times are GMT -4. The time now is 03:19 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password