× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello,

my unix skill is minimum at best. Can you please give me a bit more clue on
what you mean?

Okay, for the sake of example, let's assume the sample you posted is in a stream file named 'ewrest.dat'. The format of the example you posted happens to be legitimate syntax for a Unix shell script -- i.e., it contains statements that assign data to variables. Each variable is uniquely identified (by the number at the end of each variable name)

So the basic premise is... you don't /parse/ your file, you /run/ it! The result will be a bunch of variables in the memory of a QShell shell script. Then, you write a loop that loops through those variables and does something with them. (and I don't know what the 'something' is -- it's whatever your business logic dictates...)

So let's assume for this discussion that your data is in a file named 'ewrest.dat' and there are two "rows" of data (represented by the numbers 0 and 1.) and let's assume that, for some reason, you want the data to be written to a CSV file. (If nothing else, this makes it easy to load into a database table via CPYFRMIMPF)

Here's a Qshell script:

eval $(cat ewrest.dat)
x=0;
while test $x -lt 2; do
eval col1=\$EWREST_id_${x}
eval col2=\$EWREST_wfstate_${x}
eval col3=\$EWREST_summary_${x}
eval col4=\$EWREST_boss_ciss_customer_no_${x}
echo "\"$col1\",\"$col2\",\"$col3\",\"$col4\""
x=$((x+1))
done

The 'eval' statement means "run this code", more or less. The first line gets the contents of the ewrest.dat file (that's what "CAT" does) and runs the code it in... essentially loading the variables into memory.

The while loop loops while the variable 'x' is less than 2... since x starts at 0, that means it'll loop twice, first time set to 0, second time set to 1.

the 4 'eval' statements in the loop will set the "col1", "col2", etc variables to the values of the variables in your 'ewrest.dat' file. first time through the loop, x=0, so $EWREST_id_${x} returns the value of EWREST_id_0. etc.

the 'echo' statement writes the variables in CSV format...

So if you run this QShell script, you'll get this:

$
> ./ewrest
"861","Open","SummSumm -TW","1234"
"761","Open","Test -TW","123456789"
$

(I actually coded it up and ran it to make sure I got the details right... so the output is a copy/paste from my screen.)

to direct the CSV data into a stream file, just use a redirection operator:

$
> ./ewrest > /home/scott/hockchai_test.csv
$

does that help?

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.