LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-22-2019, 02:05 AM   #1
satyarankireddy
Member
 
Registered: Mar 2019
Posts: 48

Rep: Reputation: Disabled
Mutipule .xls files convert into single .csv


On a daily basis, I have received 20 .xls files in Linux box. Each file starts from 6 rows and converts into single.csv file.

ex:-

.xls file 1 contains 106 rows
.xls file 2 contains 206 rows
.xls file 3 contains 56 rows

all three files data convert into a single CSV file. Single CSV file count should be 350.

Using below command i can able to convert .xls file to csv with single file
unoconv -f csv -e FilterOptions="59,0,0,1" test_amount1.xls


can anyone let me know how to implement single shot to all files conversion from .xls to .csv
 
Old 09-22-2019, 04:38 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by satyarankireddy View Post
can anyone let me know how to implement single shot to all files conversion from .xls to .csv
According to the man page, unoconv can process several xls files at once:
Code:
unoconv -f csv -e FilterOptions="59,0,0,1" test_amount*.xls
I haven't tried it out, though.
 
Old 09-22-2019, 08:11 AM   #3
satyarankireddy
Member
 
Registered: Mar 2019
Posts: 48

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
According to the man page, unoconv can process several xls files at once:
Code:
unoconv -f csv -e FilterOptions="59,0,0,1" test_amount*.xls
I haven't tried it out, though.

Ok, how to add starting point line? I mean each file start with 6 row onwards ?

Awk command we can't use this command. Are there any method to tell the code to start data extraction from 6 row onwards for each file.
 
Old 09-22-2019, 08:23 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by satyarankireddy View Post
Ok, how to add starting point line? I mean each file start with 6 row onwards ?
You could use --stdout and pipe the output into awk:
Code:
unoconv ... --stdout | awk 'NR>6' > out1.csv
then cat the three files
Code:
cat out[123].csv >out.csv
I don't know what you mean by "single shot".
 
Old 09-22-2019, 08:59 AM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
this is the same question as your "solved" thread

https://www.linuxquestions.org/quest...0/#post6037519

Manpage
https://linux.die.net/man/1/unoconv

Code:
For example you might want to use this for a
real comma-separated document:

    -i 44,34,utf-8,2,1/5/2/1/3/1/4/1

which will
use a comma (44) as the field separator,
a double quote (34) as the text delimiter,
UTF-8 for the input encoding,
start from the second row
and use the specified formats for each column (1 means standard, 5 means YY/MM/DD date)
why are you having problems working this out?

Last edited by Firerat; 09-22-2019 at 09:03 AM.
 
1 members found this post helpful.
Old 09-22-2019, 09:21 AM   #6
satyarankireddy
Member
 
Registered: Mar 2019
Posts: 48

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
You could use --stdout and pipe the output into awk:
Code:
unoconv ... --stdout | awk 'NR>6' > out1.csv
then cat the three files
Code:
cat out[123].csv >out.csv
I don't know what you mean by "single shot".
how to capture files name list which are involved in below command? I mean how many files are converted from .xls to CSV , I have to capture those file names into .txt file? Does it possible?

unoconv -f csv -e FilterOptions="59,0,0,1" test_amount*.xls
 
Old 09-22-2019, 09:39 AM   #7
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by satyarankireddy View Post
how to capture files name list which are involved in below command? I mean how many files are converted from .xls to CSV , I have to capture those file names into .txt file? Does it possible?

unoconv -f csv -e FilterOptions="59,0,0,1" test_amount*.xls
I don't know if I understand your requirement. First I thought you wanted to put everything into a single file ("single shot", you said). Now?

In case you want one csv file for each xls file:
Code:
for file in *.xls
do
  unoconv .... $file | awk ..... > ${file%.xls}.csv
done
${file%.xls} strips the xls extension from the filename.
 
Old 09-22-2019, 09:56 AM   #8
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Code:
#!/bin/bash
Output="/path/to/onebigfile.csv"

for xls in /path/to/incomingDir/*.xls
do
    unoconv -f csv \
    -e FilterOptions="59,0,0,1" \
    "${xls}" \
    --stdout \
    | awk 'NR>5' "${csv}" >> "${Output}"
done
 
Old 09-22-2019, 10:36 AM   #9
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
This one does away with awk

Code:
#!/bin/bash
Output="/path/to/onebigfile.csv"
for xls in /path/to/incomingDir/*.xls
do
    unoconv -f csv \
    -e FilterOptions="59,34,76,6" \
    "${xls}" \
    --stdout \
    >> "${Output}"
done
; as field separator
" as text delimiter
utf-8 encoding
start at row
 
Old 09-22-2019, 10:47 AM   #10
satyarankireddy
Member
 
Registered: Mar 2019
Posts: 48

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
This one does away with awk

Code:
#!/bin/bash
Output="/path/to/onebigfile.csv"
for xls in /path/to/incomingDir/*.xls
do
    unoconv -f csv \
    -e FilterOptions="59,34,76,6" \
    "${xls}" \
    --stdout \
    >> "${Output}"
done
; as field separator
" as text delimiter
utf-8 encoding
start at row

Error:

unoconv: file `--stdout' does not exist.
unoconv: RuntimeException during import phase:
Office probably died. Unsupported URL <file:///conv/--stdout>: "type detection failed"
unoconv: file `--stdout' does not exist.
 
Old 09-22-2019, 10:51 AM   #11
satyarankireddy
Member
 
Registered: Mar 2019
Posts: 48

Original Poster
Rep: Reputation: Disabled
[QUOTE=satyarankireddy;6039393]Error:

Last edited by satyarankireddy; 09-22-2019 at 10:56 AM.
 
Old 09-22-2019, 10:52 AM   #12
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
post output of

Code:
unoconv --help

and did you replace /path/to/incomingDir/ with correct dir?
 
Old 09-22-2019, 10:55 AM   #13
satyarankireddy
Member
 
Registered: Mar 2019
Posts: 48

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
post output of

Code:
unoconv --help

and did you replace /path/to/incomingDir/ with correct dir?
Finally, I am able to convert all .xls file into single .csv. Everything looks good. Now, I just want to see what are the files are converted using this command. Just for audit purpose. How to inject the audit log in this code?


for input in test_amount*.xls; do
unoconv -f csv -e FilterOptions="59" --stdout $input
done > test_data.csv

Ex: If this code 10 files converted to .csv then I have to capture and store the all 10 files name into one .log file.

Last edited by satyarankireddy; 09-22-2019 at 11:20 AM.
 
Old 09-22-2019, 10:56 AM   #14
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by satyarankireddy View Post
Error:

Finally, I am able to convert all .xls file into single .csv. Everything looks good. Now, I just want to see what are the files are converted using this command. Just for audit purpose. How to inject the audit log in this code?

Code:
for input in test_amount*.xls; do
    unoconv -f csv -e FilterOptions="59,0,0,1" --stdout $input | tail -n +6 
done > test_data.csv
Ex: If this code 10 files converted to .csv then I have to capture and store the all 10 files name into one .log file.
why are you skipping line 1 and then skipping 6 lines ?

do you want to ignore the first 7 rows?


edit you are starting at row 1, then dropping 6
why not start at 7?

Last edited by Firerat; 09-22-2019 at 11:03 AM.
 
Old 09-22-2019, 10:58 AM   #15
satyarankireddy
Member
 
Registered: Mar 2019
Posts: 48

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
why are you skipping line 1 and then skipping 6 lines ?

do you want to ignore the first 7 rows?
the code was skipping first 6 rows for each file and converted to single .csv file. It is working fine as expected. Now, I want to capture files names into single .log file for audit purpose.

Do you have any idea ?

Last edited by satyarankireddy; 09-22-2019 at 11:00 AM.
 
  


Reply

Tags
linux



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to convert xls file to csv file in Linux and vice versa LXer Syndicated Linux News 0 05-05-2017 11:27 AM
LXer: How to convert xls file to csv file in Linux and vice versa LXer Syndicated Linux News 0 05-05-2017 09:06 AM
Convert xls to csv using php ajeesh.tr Programming 1 04-26-2011 07:14 PM
Perl convert csv to xls hawk__0 Programming 3 09-16-2009 09:13 AM
Script to convert csv 2 xls or odt xowl Linux - Software 1 01-16-2007 09:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration