Converting an scim .bin.user file to a stardict tab file possible with awk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting an scim .bin.user file to a stardict tab file possible with awk?
# 1  
Old 03-05-2011
[SOLVED] Converting an scim .bin.user file to a stardict tab file possible with awk?

Hi all,

Here is a scim sample.bin.user file
a string1 0
a string2 0
a string3 63
b string4 126
c string5 315
d string6 0
e string7 63
e string8 126
f string9 0

I like to convert this into a dict.tab file to be compiled by the stardict-editor. The 3rd column (frequency) of the sample.bin.user is to be deleted, and the 1st column of each line must be unique, so here is what I like to achieve

a string1 string2 string3
b string4
c string5
d string6
e string7 string8
f string9

I spent a whole nice Friday evening but still couldn't figure out a neat solution.
Smilie
Any pointer is most appreciated. Many thanks!

Last edited by hk008; 03-05-2011 at 02:01 AM..
# 2  
Old 03-05-2011
Code:
awk '{v=($1==x)?v FS $2:v RS $1 FS $2;x=$1}END{print v}' file

This User Gave Thanks to yinyuemi For This Post:
# 3  
Old 03-05-2011
awk will work if the data's not too large.
Code:
# scim.awk
{
        if(a[$1])       a[$1]=a[$1] " " $2;
        else            a[$1]=$2;
}

END {   for(k in a) print k, a[k];      }

Code:
$ awk -f scim.awk < infile > outfile

This User Gave Thanks to Corona688 For This Post:
# 4  
Old 03-05-2011
MySQL Thanks for the neat solution!

It turns out that the tab file requires a tab between the two column so I edited a bit.

awk '{v=($1==x)?v FS $2:v RS $1"\t"$2;x=$1}END{print v}' in_file > out_file

Smilie

Thanks to Corona688 too!

By the way anyone knows how to mark this thread as [SOLVED]?
# 5  
Old 03-05-2011
I think you can edit your thread title if you edit your original post.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to parse current and next row in tab-delimited file

Hi there, I would like to use awk to reformat a tab-delimited file containing three columns as follows: Data file: sample 1 173 sample 269 530 sample 687 733 sample 1699 1779 Desired output file: sample 174..265, 531..686, 734..1698 I need the value... (5 Replies)
Discussion started by: emiley
5 Replies

2. Shell Programming and Scripting

If cmd in in "A/user/bin A/bin A/user/sbin" but not "B/user/bin B/bin B/user/sbin" directory print t

there are two directories A and B if cmd in in "A/user/bin A/bin A/user/sbin" but not "B/user/bin B/bin B/user/sbin" directory print them (1 Reply)
Discussion started by: yanglei_fage
1 Replies

3. Shell Programming and Scripting

Converting to matrix-like file using AWK

Hi, Needs for statistics, doing converting Here is a sample file Input : 1|A|17,94 1|B|22,59 1|C|56,93 2|A|63,71 2|C|23,92 5|B|19,49 5|C|67,58 expecting something like that Output : 1|A|17,94|B|22,59|C|56,93 2|A|63,71|B|0|C|23,92 5|A|0|B|19,49|C|67,58 (11 Replies)
Discussion started by: fastlane3000
11 Replies

4. Shell Programming and Scripting

Converting txt file into CSV using awk or sed

Hello folks I have a txt file of information about journal articles from different fields. I need to convert this information into a format that is easier for computers to manipulate for some research that I'm doing on how articles are cited. The file has some header information and then details... (8 Replies)
Discussion started by: ksk
8 Replies

5. Shell Programming and Scripting

Help with converting Pipe delimited file to Tab Delimited

I have a file which was pipe delimited, I need to make it tab delimited. I tried with sed but no use cat file | sed 's/|//t/g' The above command substituted "/t" not tab in the place of pipe. Sample file: abc|123|2012-01-30|2012-04-28|xyz have to convert to: abc 123... (6 Replies)
Discussion started by: karumudi7
6 Replies

6. UNIX for Dummies Questions & Answers

Using awk to log transform a column in a tab-delimited text file?

How do I use awk to log transform the fifth column of a tab-delimited text file? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

7. Shell Programming and Scripting

splitting tab-delimited file with awk

Hi all, I need help to split a tab-delimited list into separate files by the filename-field. The list is already sorted ascendingly by filename, an example list would look like this; filename001 word1 word2 filename001 word3 word4 filename002 word1 word2 filename002 word3 word4... (4 Replies)
Discussion started by: perkele
4 Replies

8. UNIX for Dummies Questions & Answers

Converting Space delimited file to Tab delimited file

Hi all, I have a file with single white space delimited values, I want to convert them to a tab delimited file. I tried sed, tr ... but nothing is working. Thanks, Rajeevan D (16 Replies)
Discussion started by: jeevs81
16 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. UNIX for Dummies Questions & Answers

/bin/sh: /usr/bin/vi: No such file or directory when doing crontab

I just set up an ftp server with Red Hat 5.2. I am doing the work, I'm baby stepping, but it seems like every step I get stuck. Currently, I'm trying to set up a crontab job, but I'm getting the following message: /bin/sh: /usr/bin/vi: No such file or directory. I see that vi exists in /bin/vi,... (3 Replies)
Discussion started by: kwalter
3 Replies
Login or Register to Ask a Question