Merge left hand strings mapping to different right hand strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merge left hand strings mapping to different right hand strings
# 1  
Old 08-17-2013
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:
Code:
a=b
a=c
n=d
n=q

and so on.
i.e. Headword separated from gloss by a
Code:
=

I am giving below a live sample
Code:
بتا=बता
بتا=बित्ता
بتا=बुत्ता
بتان=बतान
بتان=बितान
بتانا=बिताना

I need the following output:
Code:
a=b/c
n=d/q

i.e. if the headword on the left hand side is repeated and maps to two different glosses on the right hand side, the similar headwords be reduced to one and the glosses that map to the head word be mapped to the head-word and each gloss be separated by a
Code:
/ (slash sign)

I work under windows and a perl or awk script would help.
At present I am using a macro to merge the data but this is huge and a script would help.
Many thanks
# 2  
Old 08-17-2013
Try:
Code:
perl -a -F"=" -nle 'push @{$x{$F[0]}},$F[1];END{for $i (keys %x) {print "$i=". join "/", @{$x{$i}}}}' file

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 08-17-2013
Many thanks for your help. The script worked just fine.
# 4  
Old 08-20-2013
Code:
awk -F = '{a[$1]=(a[$1]=="")?$2:a[$1]"/"$2}
        END{for (i in a) print i FS a[i]}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Just want to ask if there is a shorter hand to doing this one liner

Hi all, In Oracle, I am using SQL*Plus and selecting all rows in a table and spooling to a file as pipe delimited. I have to use pagesize 0 but unfortunately, using this option excludes the header and I can't get around having it to display the header fields. So to get around this, I have to... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Matching number of syllables on right-hand and left side

I am developing a database for translating names. I have mapped through a rule engine syllables in English to syllables in Indic, delimited by an equal to sign. An example will illustrate this ra m=रा म ku ma r=कु मा र mo=मो la l=ला ल gi ta=गी ता ka la va ti=कa ला वa ती However it so... (3 Replies)
Discussion started by: gimley
3 Replies

3. Shell Programming and Scripting

Copying of multiple columns of one table to another by mapping with particular strings.

Hi, I would like to copy some columns from a particular file by mapping with the string names. i am using the .csv file format. my one file consist of 100 of columns but i want only particular 4 columns such as ( First_name, Middle_name,Last_name & Stlc). but they are listed in many files... (15 Replies)
Discussion started by: dsh007
15 Replies

4. UNIX Desktop Questions & Answers

Old hand to FreeBSD, brand new to KDE ??'s

I have now used FreeBSD from eh, 5.0??? But during that whole time I have never used xwindows or kde. My box's have always been servers of one type or another. I just set up a new BSD machine(8.0), and because I wanted to install boinc I knew that I would have to also install xwindows. Just the... (4 Replies)
Discussion started by: droolin
4 Replies

5. Debian

change initramfs by hand?

What's the correct way to change the initramfs file that's used during boot? I know that it's a gzipped cpio archive, but when I gunzip, extract, re-archive (without changing any files), and gzip, then the result is that the system does not boot any more. And I even set the cpio archive type. ... (18 Replies)
Discussion started by: frankie06
18 Replies

6. Shell Programming and Scripting

AWK how to strip from right hand side

guys, i am writing a .ksh file to ssh to a remote machine and change all occurances of .ixf to .WIP like this : -->>> for i in *.ixf do echo $i done mv $i $i.WIP exit <<--- --> this returns .ixf.WIP - i can live with that. then i need to sftp from another remote machine, copy the files... (5 Replies)
Discussion started by: angelolamberti
5 Replies

7. Shell Programming and Scripting

Need a hand. Please?

i have a script in sh. with awk, e.g. want to list all the contents of a subdirectory an a tabular way. ej: outoput directory1 subdirectory1 subdirectory2 subdirectory3 file1 filen file2 filez file2 ... filen+1 ... (1 Reply)
Discussion started by: alexcol
1 Replies

8. Shell Programming and Scripting

How to get the most left hand string ??

Hi, I remember once seeing a way to get the left most string in a word. Let's say: a="First.Second.Third" (separated by dot) echo ${a#*.} shows --> Second.Third echo ${a##*.} shows --> Third How do I get the the left most string "First" Or "First.Second" ??? Tried to replace #... (2 Replies)
Discussion started by: jfortes
2 Replies

9. Post Here to Contact Site Administrators and Moderators

Lets give Neo a hand.

Neo, Just wanted to let you know that we all appricate the hardwork that you and your team put in to make this forum what it is. I have been a member since 05-23-2001 and i can honestly say this is one forum that is deffinetly a main stay and a true benifit to everyone that uses it. Mike... (4 Replies)
Discussion started by: Optimus_P
4 Replies

10. UNIX for Dummies Questions & Answers

Give us a hand

How do you get an awk output into columns i.e. awk (print $1,$2,$3) doesn't come out into nice columns but lots of lines of txt want something more like. I am crap at unix so give me a hand thx Rich (3 Replies)
Discussion started by: RichardB
3 Replies
Login or Register to Ask a Question