Merge strings from a file into a template


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merge strings from a file into a template
# 1  
Old 12-26-2016
Merge strings from a file into a template

I am preparing a morphological grammar of Marathi to be placed in open-source.
I have two files.
The first file called Adverbs contains a whole list of words, one word per line
A sample is given below:
Code:
आधी
इतक
इतपत
उलट
एवढ
ऐवजी
कड
कडनं
कडल
कडील
कडून
कडे
करता
करिता
खाल
खालती

The second file called Template is a template in which the Adverbs from the first file have to be inserted. The string to be replaced is shown by a symbol
Code:
|

A small sample of the template is provided below:
Code:
ं+|+ही
चा+|+ही
ची+|+ही
चे+|+ही
च्या+|+ही
च्यां+|+ही
|+ही
|+ही+च
|+ही+चं
|+ही+चं+च
|+ही+चा
|+ही+चा+च
|+ही+ची
|+ही+ची+च
|+ही+चे
|+ही+चे+च
|+ही+च्या
|+ही+च्या+च
यां+|+ही

What I am looking for is a script in Perl or Awk which will take each word from the Adverb file, insert it into the template file and put the output of all such insertions in a third file
I work in a Windows environment.
On the occasion of the New Year, may I thank all the members who so unselfishly give their time and efforts to help out by not only providing solutions, but generously comment their code.
Thank you one and all and all good wishes for the New year 2017.
# 2  
Old 12-26-2016
Unfortunately I can't verify the result, and you didn't provide an output sample, Howsoever, try
Code:
awk 'NR == FNR {T[$0]; next} {for (t in T) {D = $0; sub ("\|", t, D); print D}}' Adverbs template

and comment back.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 12-26-2016
It worked perfectly. I could merge the sample files without any effort. Many thanks. Sorry for the delay but the site seemed to be down.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

2. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

3. Shell Programming and Scripting

Merge strings with ignore case

I have a bi-lingual database of a large number of dictionaries. It so happens that in some a given string is in upper case and in others it is in lower case. An example will illustrate the issue. toll Tax=पथ-कर Toll tax=राहदारी कर toll tax=टोल I want to treat all three instances of toll tax... (3 Replies)
Discussion started by: gimley
3 Replies

4. Shell Programming and Scripting

Inputing info from a CSV file and filling a template file

Hi, I have a .csv file that contains a variety of fields for 60 clients: USERNAME, PASSWORD, and COMMENTS. I have a template file which contains a great deal of data for each client and has the fields USERNAME, PASSWORD, and COMMENTS that has to be filled with the values of USERNAME,... (1 Reply)
Discussion started by: mojoman
1 Replies

5. Programming

Perl script to merge cells in column1 which has same strings, for all sheets in a excel workbook

Perl script to merge cells ---------- Post updated at 12:59 AM ---------- Previous update was at 12:54 AM ---------- I am using below code to read files from a dir and print to excel. open(my $in, '<', $file) or die "Could not open file: $!"; my $rowCount = 0; my $colCount = 0;... (11 Replies)
Discussion started by: Jack_Bruce
11 Replies

6. Programming

Merge two strings by overlapped region

Hello, I am trying to concatenate two strings by merging the overlapped region. E.g. Seq1=ACGTGCCC Seq2=CCCCCGTGTGTGT Seq_merged=ACGTGCCCCCGTGTGTGTFunction strcat(char *dest, char *src) appends the src string to the dest string, ignoring the overlapped parts (prefix of src and suffix of dest).... (30 Replies)
Discussion started by: yifangt
30 Replies

7. Shell Programming and Scripting

Merge left hand strings mapping to different right hand strings

Hello, I am working on an Urdu to Hindi dictionary which has the following structure: a=b a=c n=d n=q and so on. i.e. Headword separated from gloss by a = I am giving below a live sample بتا=बता بتا=बित्ता بتا=बुत्ता بتان=बतान بتان=बितान بتانا=बिताना I need the following... (3 Replies)
Discussion started by: gimley
3 Replies

8. Shell Programming and Scripting

filling in strings in a template file using awk

Hi all, I have a template form to fill in for quite a number of files and I want to automate the filling-in process. the concept seemed to be simple but i cant get it work. the template form is a text file containing the information below: File Name: Date Created: Contents: I need to... (4 Replies)
Discussion started by: ida1215
4 Replies

9. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

10. UNIX for Dummies Questions & Answers

Merge two strings not from files

str1="this oracle data base record" str2="one two three four five" Output: this one oracle two data three base four record five str1 and str2 have the same column but they are not fixed columns. I can do it with "paste" but I do not want to create file everytime the script runs from... (2 Replies)
Discussion started by: buddyme
2 Replies
Login or Register to Ask a Question