LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-24-2019, 11:55 AM   #16
jaybiano
LQ Newbie
 
Registered: Oct 2019
Location: New York
Posts: 9

Original Poster
Rep: Reputation: Disabled

@TBOne the output would be used for Lawson payroll system.
Thanks, i just started learning Bash scripting, i will look into perl and Python as well

When i excute the script i get this lines of error, is there a reason perl isn't work for me?


tondsd06:dcapps> fileRead.sh Monthsal.csv
Can't locate Time/Piece.pm in @INC (@INC contains: /usr/lib/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl .) at ./fileRead.sh line 4.
BEGIN failed--compilation aborted at ./fileRead.sh line 4.




if i do
Code:
#!/bin/bash    ---- This works
But

Code:
#!/usr/bin/perl   ----- Does not work

Last edited by jaybiano; 10-24-2019 at 11:57 AM.
 
Old 10-24-2019, 12:03 PM   #17
jaybiano
LQ Newbie
 
Registered: Oct 2019
Location: New York
Posts: 9

Original Poster
Rep: Reputation: Disabled
@Firerat, i'm still getting same error with code

Code:
 The Error 
tondsd06:dcapps> fileRead.sh Monthsal.csv
./fileRead.sh: line 13: printf: 3 9 2019: invalid number
: invalid numberine 13: printf: 209299
750-85665-3 0000233420 000000000000000000
./fileRead.sh: line 13: printf: 3 9 2019: invalid number
: invalid numberine 13: printf: 285615
750-85665-3 0000233417 000000000000000000
 
Old 10-24-2019, 12:14 PM   #18
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
does that code have the No. of field checks in it?

I also included some debugging bits earlier, to print fields

another
Code:
#printf "%s %s %02d%02d%02d%012d\n" \
printf "%s %s _%s_%s_%s_%012d\n" \

but if the "Lawson" can take the original csv without modification ultimately that is what you should use.
I assume some kind of import filter would have to be configured

Last edited by Firerat; 10-24-2019 at 12:17 PM. Reason: typo
 
1 members found this post helpful.
Old 10-24-2019, 12:14 PM   #19
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by jaybiano View Post
@TBOne the output would be used for Lawson payroll system.
Thanks, i just started learning Bash scripting, i will look into perl and Python as well

When i excute the script i get this lines of error, is there a reason perl isn't work for me?
Code:
Can't locate Time/Piece.pm in @INC (@INC contains: /usr/lib/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl .) at ./fileRead.sh line 4.
BEGIN failed--compilation aborted at ./fileRead.sh line 4.
This isn't a shell script (.sh)...this is a perl program, so name if "fileRead.pl" instead. While extensions don't matter to Linux, it *WILL* matter to you later, because you'll need to keep track of things, what they are and what they do. Something like "fileRead" isn't descriptive, so if you put this in a job scheduler, along with OTHER programs, make your life easy. Name it something like "LawsonFileConverter.pl" or something like that.

And you're getting that error because the Time::Piece module for perl isn't installed on your system. You don't say what version/distro of Linux you're using, but chances are it's in the repositories. And *AGAIN* when posting such output, you need to put it in CODE tags.
Quote:
if i do
Code:
#!/bin/bash    ---- This works
But
Code:
#!/usr/bin/perl   ----- Does not work
Define "does not work", please. If you're putting the actual "#!" in front of it, it won't....and if you just run /usr/bin/perl, it will only give you a blank line, since you're entered into the perl compiler...it's expecting you to put in code. Running /bin/bash only brings up a new shell, invisibly...your original shell is still running.
 
1 members found this post helpful.
Old 10-24-2019, 12:25 PM   #20
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
can you also give output of

Code:
bash -x fileRead.sh Monthsal.csv
or

Code:
#!/bin/bash
input="${1:-./input.csv}"
set -x
while IFS=, read -r -a CSV
do
  [[ ${#CSV[@]} != 5 ]] \
    && echo "error No. of fields incorrect" \
    && break
  [[ ${CSV[0]} =~ ^Account ]] && continue
  #[[ ${CSV[1]} ==  NONREF ]] && continue
  [[ ${#CSV[1]} -lt 10 ]] \
    && CSV[1]="${CSV[1]/#/$(printf "%0$(( 10 - ${#CSV[1]} ))d" 0 )}"
  IFS=/ read -a Date <<<${CSV[2]}
  printf "%s %s %02d%02d%02d%012d\n" \
    "${CSV[0]:0:3}-${CSV[0]:3:5}-${CSV[0]:(-1)}" \
    "${CSV[1]}" \
    "${Date[1]}" "${Date[0]}" "${Date[2]:(-2)}" \
    "${CSV[4]//[.-]}"
exit
done < "${input}"
set -x will show expansions
and exit will exit after first full loop
 
  


Reply



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
creating a script that would read in a csv file and output the data in a different format to load into the Lawson payroll system jaybiano Linux - Newbie 2 10-23-2019 03:10 PM
How to print lines in csv file if 1 csv column field = "text". There are 10 column (;) in csv file nexuslinux Linux - Newbie 9 04-22-2016 11:35 PM
[SOLVED] A challenging script - Replace field of CSV file based on another CSV file arbex5 Programming 11 06-12-2013 06:56 AM
Putty using csv files in BASH to format file in script as output smks Linux - Newbie 7 12-22-2011 05:50 PM
Comparing two csv files and write different record in third CSV file irfanb146 Linux - Newbie 3 06-30-2008 09:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:45 AM.

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