Awkscript to reduce words delimited with comma on right hand to columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awkscript to reduce words delimited with comma on right hand to columns
# 1  
Old 04-30-2017
Awkscript to reduce words delimited with comma on right hand to columns

I have a large database with the following structure:
Code:
Indicword,Indicword,Indicword=English

on a line.
Not all lines will have this structure. Some might have a single word mapping to a single word in Indic.
An example will make this clear
Code:
अथक,अश्रांत,मेहनती,परिश्रमी,कष्टाळू,कामसू,श्रमी,खपती=tireless
अथक,अश्रांत=indefatigable
अथक,अश्रांत=unflagging
अथक,अश्रांत=unwearying
अथांग,अगाध,सखोल,गहन=unfathomed
अथांग,अगाध,सखोल,गहन=unplumbed
अथांग,अगाध,सखोल,गहन=unsounded
अदंडित=unpunished
अदम्य,दुर्दम्य=indomitable
अदम्य,दुर्दम्य=never-say-die
अदम्य,दुर्दम्य=that which cannot be subdued
अदाह्य,अदहनीय=fireproof
अदूरदृष्टी,अदूरदर्शी=myopic
अदूरदृष्टी,अदूरदर्शी=shortsighted
अदूरदृष्टी,अदूरदर्शी=not having foresight
अदृश्य,अदृष्ट=invisible
अद्राव्य,अद्रावणीय,अविद्राव्य,अविघटनशील=indissoluble
अद्राव्य,अद्रावणीय,अविद्राव्य,अविघटनशील=insoluble

I wanted to map each Indicword separated by a comma to it corresponding English gloss as in the short example below.
Code:
अदृश्य=invisible
अदृष्ट=invisible

I wrote an awk script to handle the issue, but the results are skewed. Here is the script:
Code:
BEGIN{FS="="}
{n=split($1,a," ");split($2,b," ");for (i=1;i<=n;i++) print a[i]"="b[i]}

Why is the script not executing the way it is meant to do?
Many thanks for your help and if you could comment the awk script, that would be most helpful.
# 2  
Old 04-30-2017
Consolidate the fields:
Code:
 awk -F '[,=]' '{ for(i=1; i<NF; i++) { printf("%s=%s\n", $(i), $(NF) )}} ' filename > newfile

This will not work with older versions of awk.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 04-30-2017
Thanks a lot. I have an older awk version and as you said it did not run with it it. I will download awk for Windows10 and will try out with that
# 4  
Old 04-30-2017
Why not adapt / improve your own approach:
Code:
awk 'BEGIN{FS="="}                                                              
{n=split($1,a,",");for (i=1;i<=n;i++) print a[i]"="$2}' file

This User Gave Thanks to RudiC For This Post:
# 5  
Old 04-30-2017
Many thanks.
it worked perfectly. I checked with the one I had written and understood the mistake I had made.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modify comma delimited file columns.

Please help me to update a file which contains date values as below:- From:- "1912108",20161130,"2016-12-01-00.00.00.000000","2016-12-01-08.37.12.000000" "1912108",20161201,"2016-12-02-00.00.00.000000","2016-12-02-08.28.22.000000" To:- "1912108",2016-11-30,"2016-12-01... (7 Replies)
Discussion started by: KrishnaVM
7 Replies

2. Shell Programming and Scripting

Help/Advise please for converting space delimited string variable to comma delimited with quote

Hi, I am wanting to create a script that will construct a SQL statement based on a a space delimited string that it read from a config file. Example of the SQL will be For example, it will read a string like "AAA BBB CCC" and assign to a variable named IN_STRING. I then concatenate... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. Shell Programming and Scripting

Transpose comma delimited data in rows to columns

Hello, I have a bilingual database with the following structure a,b,c=d,e,f The right half is in a Left to right script and the second is in a Right to left script as the examples below show What I need is to separate out the database such that the first word on the left hand matches the first... (4 Replies)
Discussion started by: gimley
4 Replies

4. Homework & Coursework Questions

ASCII comma-delimited

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi Guys, I am new on the scripting world and would like ask for help if you can. Here are my questions... (1 Reply)
Discussion started by: mahiwaga
1 Replies

5. Shell Programming and Scripting

How can i comma-delimited last field in line?

Awk gurus, Greatly appreciate for any kind of assistance from the expert community Input line: abc,11.22.33.44,xyz,7-8-9-10 pqr,111.222.333.444,wxy,1-2-3 def,22.33.44.55,stu,7-8 used the gsub function below but it changes all of the "-" delimiter: awk 'gsub("-",",")' Desired... (4 Replies)
Discussion started by: ux4me
4 Replies

6. Shell Programming and Scripting

Need a script to convert comma delimited files to semi colon delimited

Hi All, I need a unix script to convert .csv files to .skv files (changing a comma delimited file to a semi colon delimited file). I am a unix newbie and so don't know where to start. The script will be scheduled using cron and needs to convert each .csv file in a particular folder to a .skv... (4 Replies)
Discussion started by: CarpKing
4 Replies

7. UNIX for Dummies Questions & Answers

Comma delimited file

Hi All, I have output of sql saved in comma separated file. Now i need to read line by line this file and assign word to a unix variable for further processing Eg: Test file world, 1, 3, 4 earth,2,3,4,5 moon,1,2,3,4 Output should be word1= world word2=1 echo " first word... (7 Replies)
Discussion started by: gwrm
7 Replies

8. Shell Programming and Scripting

separating comma delimited words

Hi, I have file with text ________________________________ GROUP:firstname1.lastname1,first_name2.last_name2,first_name3.last_name3 HEAD:firstname.lastname ________________________________ I need help to pick the names separately ie.. Need out put as var1 =firstname1.lastname1... (4 Replies)
Discussion started by: rider29
4 Replies

9. Shell Programming and Scripting

Converting Tab delimited file to Comma delimited file in Unix

Hi, Can anyone let me know on how to convert a Tab delimited file to Comma delimited file in Unix Thanks!! (22 Replies)
Discussion started by: charan81
22 Replies

10. Shell Programming and Scripting

Comma Delimited file

I have a comma delimited file that sometimes has addresses details in. The problem is that the address detail can be seen as: "Sample House, Sample Road". When I run a script specifying the file is comma delimited I would like it to ignore comma's that are in between speech marks. Is this... (2 Replies)
Discussion started by: dbrundrett
2 Replies
Login or Register to Ask a Question