|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#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: 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. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
What output would you want for that input?
|
| Sponsored Links | ||
|
|
#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 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
|
|||
|
|||
|
Code:
awk 'NR==FNR { A[$1]=1; next } $1 in A' file2 file1 |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
syntax error Corona
|
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Which syntax error?
Use nawk on solaris. |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Maybe it should be: Code:
awk 'NR==FNR { A[$1]=$1; next } $1 in A' file2 file1
^
MissingSorry, 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)
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 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 |
| 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 |
| Use of uninitialized value in join or string at arraydef.pl | praveen_b744 | Shell Programming and Scripting | 5 | 08-31-2007 10:09 AM |
|
|