Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in
# 1  
Old 01-26-2018
Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears
i have text file like this:
INPUT.txt
Code:
001_1_173    j                          nuh                        ]az
001_1_174    j                          ]esma.                        nuh                        ]/.xori
.
.
.

and have another text
like this
TABLE.txt
Code:
j j
nuh word1
]az word2
]esma. word3
]/.xori word 4
.
.
.

i want to that all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in.

for example output must like that
OUTPUT.txt
Code:
001_1_173 j word1 word2
001_1_174 j word3 word1 word4

column1 in INPUT.txt must copy in column1 of OUTPUT.txt.
number of columns in INPUT.txt not the same.


thanks all.

Last edited by alii; 01-27-2018 at 08:52 AM.. Reason: solved
# 2  
Old 01-26-2018
Hello alii...

First of all put your requirements inside code tags
Code:
 something like this

as per the site's requirements.
Next, what have you attempted so far.
Which Operating System you are using.
Which shell is your preference.
What are the OS and Shell versions that you have.
Your _preferred_ utilities to attain the results...
# 3  
Old 01-26-2018
Code:
awk '
NR==FNR {w[$1]=$2; next;}
{for (i=2; i<=NF; i++) if ($i in w) $i=w[$i]; print $0;}
' TABLE.txt INPUT.txt

This User Gave Thanks to rdrtx1 For This Post:
# 4  
Old 01-26-2018
One might also consider explaining how the 3rd column in TABLE.txt is supposed to be used.

It appears that you want ]/.xori to be translated to word4, but column 2 in TABLE.txt on the line with ]/.xori has word in column 2 on that line and 4 in column 3; not word4, Your description didn't say anything about a column 3 in TABLE.txt. Smilie
# 5  
Old 01-27-2018
search last column of INPUT in TABLEs text and add correspond columns to INPUT

thanks all
i use UBUNTU 16.04 LTS
it's ok.
may explain your code?


so another question
i have INPUT
like this
see last column
number of columns different in one
some row have 12 , some 11

Code:
INPUT
CodeGender Age Grade Dialect Session Sentence Start End Length Phonemic Phonetic 
63 M 27 BS/BA TEHRANI 3 4 298320 310050 11730 j j 
63 M 27 BS/BA TEHRANI 3 4 310050 311430 1380 ( a 
63 M 27 BS/BA TEHRANI 3 4 311430 312080 650 ] ]

and two TABLE text like this.have two columns.
Code:
TABLE1
j feat1
a feat2
.
.
.

Code:
TABLE2
j sp1
a sp2
.
.

I want to add two columns to INPUT
search last column of INPUT in TABLEs text and add correspond columns to INPUT
(i think can merge TABLEs like j feat1 sp1)
and output like this
Code:
output
CodeGender Age Grade Dialect Session Sentence Start End Length Phonemic Phonetic feat sp
63 M 27 BS/BA TEHRANI 3 4 298320 310050 11730 j j feat1 sp1
63 M 27 BS/BA TEHRANI 3 4 310050 311430 1380 ( a feat2 sp2
63 M 27 BS/BA TEHRANI 3 4 311430 312080 650 ] ]


Last edited by alii; 01-27-2018 at 06:02 AM.. Reason: Misspelling
# 6  
Old 01-27-2018
Moderator's Comments:
Mod Comment Please start a new thread for your new problem.

Asking people to explain code for one problem while asking for new code for a new problem in one thread is a great way to confuse people who are try to help you and to confuse people who are reading your thread and trying to learn from the problem(s) presented therein.
This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 01-27-2018
sorry about that
thanks for your guides
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search last column of INPUT.txt in TABLEs text and add correspond columns to INPUT.txt

Hi dears i use bash shell i have INPUT.txt like this number of columns different in one some row have 12 , some 11 columns see last column INPUT.txt CodeGender Age Grade Dialect Session Sentence Start End Length Phonemic Phonetic 63 M 27 BS/BA TEHRANI 3 4 298320 310050... (2 Replies)
Discussion started by: alii
2 Replies

2. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

3. Shell Programming and Scripting

Convert shell script output txt file to html table

My concnern related to the post -Convert shell script output txt file to html table, in this how to print the heading as color. awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' <filename> (8 Replies)
Discussion started by: sarajobmai
8 Replies

4. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

5. Shell Programming and Scripting

Read input txt while find copy

I have a text file called file.txt which has a list of file as shown below that i need to find and copy to a particular location. FILENAMES skter.pdf abcdf.sas tereen.lst abc12.txt i am using following code and it never works however i try it. cat file.txt | while read FILENAME;do find... (4 Replies)
Discussion started by: MILAN KUMAR
4 Replies

6. UNIX for Dummies Questions & Answers

How to Update DB table from txt file using CRONJOB in Unix Shell Script

Hi Experts, can guide how we can Update a Database Table using a txt file source Using Unix Shell Scripts. What are the Cron Jobs codes can written to Update DB table. txt file contains record like data. US 09/03/2012 User DocType DocID. these above feilds in txt files need to be updated in... (4 Replies)
Discussion started by: mahesh.sap
4 Replies

7. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

8. Shell Programming and Scripting

Convert shell script output txt file to html table

Hi, I have script which generates the output as below: Jobname Date Time Status abc 12/9/11 17:00 Completed xyz 13/9/11 21:00 Running I have the output as a text file. I need to convert it into a HTML Table and sent it thru email ... (6 Replies)
Discussion started by: a12ka4
6 Replies

9. UNIX for Dummies Questions & Answers

find lines in file1.txt not found in file2.txt memory problem

I have a diff command that does what I want but when comparing large text/log files, it uses up all the memory I have (sometimes over 8gig of memory) diff file1.txt file2.txt | grep '^<'| awk '{$1="";print $0}' | sed 's/^ *//' Is there a better more efficient way to find the lines in one file... (5 Replies)
Discussion started by: raptor25
5 Replies

10. Shell Programming and Scripting

sed to read x.txt and grep from y.txt

How would I write a command(s) to read from a file (list) that looks like this: 29847374384 and grep from a second file (list) that looks like this: 29847374384, jkdfkjdf,3833,ddd:confused: (1 Reply)
Discussion started by: smellylizzard
1 Replies
Login or Register to Ask a Question