Read data from .csv file through shell script & modify

I need to read data from a file called "test.csv" through shell script where the file contains values like name,price,descriptor etc. There are rows where descriptor (& in some rows name) are written as string & other characters like "car_+" OR "bike*" etc where it should contains strings like "car" OR "bike".

Problem is I need to read that file & take out error rows & write those rows into a new file say error.csv & update test.csv with correct rows.

Please let me know how to read & check these things & then update.
OS can be either AIX/HP-UX/Sun-Solaris. Suppose script is bourne shell script.

Thanks,
Raj

Post the following:
(1) Your sample input file.
(2) Your desired output.

Give us something to work with.

tyler_durden

Alright sample input file : (ofcourse this is not the original file but the original file I need to work is similar to this containing more rows & columns. Original file is office confidential.)

File test.csv :
----------------------------------------------------------------
name price descriptor
Car 50 Mustang
Car_ 70 Audi A5
Bike 30 BMW)
SUV@ 80 Fortuner+_
Car 75 Sierra
--------------------------------
1st row is fine
2nd row -> underscore(car_) need to remove it & put it in a file called error.csv
3rd row -> closing brace ) after BMW & again this row should go to error.csv
4th row -> error at 1st column & last column should go to error.csv
5th row is fine
-----

Now Rows 2, 3 & 4 contain error & they need to be written to error file called error.csv & update test.csv with correct rows. Error rows need not be present in test.csv after these checks.

"csv" means "comma separated values". There are no commas in your "test.csv" file, so I'll assume your file looks like the one in the following excerpt -

$
$
$ # show the content of the csv file "f3"
$
$ cat f3
name,price,descriptor
Car,50,Mustang
Car_,70,Audi A5
Bike,30,BMW)
SUV@,80,Fortuner+_
Car,75,Sierra
$
$ # run the awk one-liner to process "f3"
$
$ awk -F, 'NR>1 {if ($1 !~ /^[a-zA-Z0-9 ]+$/ || $3 !~ /^[a-zA-Z0-9 ]+$/){print $0 >"f3.err"} else {print $0 >"f3.tmp"}}' f3 ; mv f3.tmp f3
$
$ # show the content of the error file "f3.err"
$
$ cat f3.err
Car_,70,Audi A5
Bike,30,BMW)
SUV@,80,Fortuner+_
$
$ # show the content of the updated csv file "f3"
$
$ cat f3
Car,50,Mustang
Car,75,Sierra
$
$

tyler_durden