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.

Grep from FileA, search in FileB, edit FileC > Output

Login or Register to Reply

Thread Tools Search this Thread
# 1  
Grep from FileA, search in FileB, edit FileC > Output

Similar question to my previous posts. I am sorry for the trouble...
Just checked my old threads but I can not implement any solution into this case..
My aim is to grab each line in fileA, check it in fileB and merge with fileC (tab separated) in corresponding line as given below:
FileA: just nba teams,
FileB: nba teams with a couple of team players (team-player-team-player-team-player)
FileC: my current file
Output: merged output
Golden State Warriors
Boston Celtics
New York Knicks
Toronto Raptors
Chicago Bulls

Golden State Warriors
Golden State Warriors

Boston Celtics
Boston Celtics

New York Knicks
New York Knicks
New York Knicks

Golden State Warriors	Jordan_Bell
Boston_Celtics	Jaylen_Brown
New York Knicks	Henry_Ellenson
Toronto_Raptors	OG_Anunoby
Chicago Bulls	Raw_Alkins

Golden State Warriors	Jordan_Bell	Andrew_Bogut	Quinn_Cook
Boston Celtics	Jaylen_Brown	PJ_Dozier	Jonathan_Gibson
New York Knicks	Henry_Ellenson		Mario_Hezonja	Isaiah_Hicks	John_Jenkins
Toronto_Raptors		OG_Anunoby
Chicago Bulls	Raw_Alkins

Multiple loops caused intensive headache here..
I'd appreciate your help..

Edit: I am near to solution with awk.. Working on it...

I think that Vgersh's old post will do that...
awk -f test.awk FileA FileB FileC

FNR==NR { a[$1];next}
$1 in a {a[$1]=a[$1] OFS $2}
  for (i in a)
    print i,a[i]

Solved: Even though file format is a bit different, it works with some extra manipulation.

Thank you

Last edited by baris35; 05-18-2019 at 02:29 PM..
# 2  
I don't think that will fly. You seem to use underscores and spaces in team names inconsistently, don't set the correct OFS variable, and your file2 doesn't have a meaningful $2 in the structure that you show and describe.
Try instead
awk -F"\t" '
FNR == 1        {++FC
FC == 1         {a[$1]
FC == 2 && NF   {getline T
                 a[$1] = a[$1] (a[$1]?OFS:"")  T
NF              {print $0, a[$1]
                 delete a[$1]
' OFS="\t" fileA fileB fileC
 Golden State Warriors	Jordan Bell	Andrew Bogut	Quinn Cook
Boston Celtics	Jaylen Brown	PJ Dozier	Jonathan Gibson
New York Knicks	Henry Ellenson	Mario Hezonja	Isaiah Hicks	John Jenkins
Toronto Raptors	OG Anunoby	
Chicago Bulls	Raw Alkins	

These 2 Users Gave Thanks to RudiC For This Post:
# 3  
Thank you Rudic,
I had to change the files while testing but I will run as you leaded.

Kind regards
Login or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
awk or grep to search one column and output the other
Hello, it would be great if someone can help me with the following: I want to search for the rows from fileA in column 1 of fileB and output column 2 of fileB if found in fileC. In the moment I search within the complete file. How can I change the code so only column 1 is searched? cat fileA...... Shell Programming and Scripting
Shell Programming and Scripting
Perl search csv fileA where two strings exist on another csv fileB
Hi I have two csv files, with the following formats: FileA.log: Application, This occured blah Application, That occured blah Application, Also this AnotherLog, Bob did this AnotherLog, Dave did that FileB.log: Uk, London, Application, datetime, LaterDateTime, Today it had'nt...... Shell Programming and Scripting
Shell Programming and Scripting
Copying lines from fileA if they start by a word from fileB
Hi I'm in the need of a script that basically takes two files and generates a 3rd. It reads from fileA and fileB and copies lines from fileA if they start by a word of fileB. for example fileA The dog is beautful Where is your cat Why are you sad? Help me! fileB The Where tree dog...... Shell Programming and Scripting
Shell Programming and Scripting
cat file1 read line-per-line then grep -A 15 lines down in fileb
STEP 1 # Set variable FILE=/tmp/mainfile SEARCHFILE =/tmp/searchfile # THIS IS THE MAIN FILE. cat /tmp/mainfile Interface Ethernet0/0 "outside", is up, line protocol is up Hardware is i82546GB rev03, BW 100 Mbps Full-Duplex(Full-duplex), 100 Mbps(100 Mbps) MAC address...... Shell Programming and Scripting
Shell Programming and Scripting
How search,edit and save the file
Hi All, I want to edit a file using shell script..For ex...a file called /etc/ I am searching for "ftp" if it is there just change it to "tftp" without using any temporary file.... Shell Programming and Scripting
Shell Programming and Scripting

Featured Tech Videos