How to get the data from Libre Office Calc and use it in a bash script?

I am Using Ubuntu 20.04.1

I have Libre Office Calc. with two columns working.
I do edit these two columns weekly once..

A 987654320
B 987654321
C 987654322
D 987654323
E 987654324
F 987654325
G 987654326

I need to write a bash script that gets the data from the above two columns and make a text file like below as an example..

BEGIN:VCARD
VERSION:3.0
FN:$(content of column1, row1)
N:$(content of column1,row1)
TEL;TYPE=cell:$(content of column2, row1)
END:VCARD
BEGIN:VCARD
VERSION:3.0
FN:$(content of column1, row2)
N:$(content of column1,row2)
TEL;TYPE=cell:$(content of column2, row2)
END:VCARD
and so on till it finds the content at last existing row
3

1 Answer

We can get the needed result with two-step process:

  1. we convert spreadsheet to file.txt (really CSV):

    localc --headless --convert-to txt:"Text - txt - csv (StarCalc)" file.ods
  2. use some AWK scripting:

    awk -F, '{
    print "BEGIN:VCARD"
    print "VERSION:3.0"
    print "FN:"$1
    print "N:"$1
    print "TEL;TYPE=cell:"$2
    print "END:VCARD"
    print ""
    }' file.txt 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like