Search two file types within a for loop

I need to search for a csv and a dat file within a for loop then output them to a log table. I can do it individually but I want them together.

See below code:

check csv

    count=0
    for file in $\(ls *.csv\) ; 
    do
        count=\`expr $count \+ 1\`

        writelogf "$argv0: \+%-50.50s\+\\n" $ul
        writelogf "$argv0: |%-50.50s$\{cs\}\\n" "FILE IN"
        writelogf "$argv0: \+%-50.50s\+\\n" $ul
        writelogf "$argv0: |%-50.50s$\{cs\}\\n" $\{file%*\}
        writelogf "$argv0: \+%-50.50s\+\\n" $ul
     
    done

this gives me the following output:

x.sh: +--------------------------------------------------+
x.sh: |FILE IN |
x.sh: +--------------------------------------------------+
x.sh: |x.csv |
x.sh: +--------------------------------------------------+

I repeat the same type of code for the .dat files and get
x.sh: +--------------------------------------------------+
x.sh: |FILE OUT |
x.sh: +--------------------------------------------------+
x.sh: |x.dat |
x.sh: +--------------------------------------------------+

How can i merge together within one for loop to give me this output:

x.sh: +------------+------------+
x.sh: |FILE IN | FILE OUT |
x.sh: +------------+------------+
x.sh: |x.csv | x.dat |
x.sh: +------------+------------+

the table does not come out like i want it to on the post but you get the idea

:confused:

ls *csv *dat 2>/dev/null

see, 2>/dev/null is important

Well, the output format you will need to work on (it wont take much more then what you currently have), to find .csv and .dat files, that wouldn't be too hard.

find . -type f | egrep -i "(csv|dat)$"

You would want to do an if statement to check to see if the filenames end with the dat/csv extension in the loop and then output appropriate data.

I'm not sure how to use syntax below into my current code to get the answer i'm looking for?

more information: both files csv and dat start with the same name i.e. pb_xxxx.csv pb_xxxx.dat.

I change these files from a csv to a fixed length file

I need them to line up in the table:

x.sh: +------------+------------+
x.sh: |FILE IN | FILE OUT |
x.sh: +------------+------------+
x.sh: |pb_123.csv | pb_123.dat |
x.sh: +------------+------------+
x.sh: |pb_456.csv | pb_456.dat |
x.sh: +------------+------------+

I'm not sure the for loop can do this????? i maybe wrong

no need to use egrep..

find . -type f \( -name "*.csv" -o -name "*.dat" \)