special characters giving problem

Hi All,

I have a CSV file in which some fields contains special character for ex:-

my file is file 1

cat file1
abcd,bgfht,ngbht,abvc ****
hdlld,hsgdt,bhfy,knht ****

whenever i am trying to put a 4th feild in a variable its giving me list of all the files i have in current directory like:-

cat file1|while read line
do
 
VARIABLE=`echo $line|awk -F "," '{print $4}'`
done

instead of giving abvc **** and knht **** in a variable its giving me
abvc file1 file2 file3...etc all the files which i have in my directory.:frowning:

Please suggest.

Regards,
SAM

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 17:34 ---------- Previous update was at 17:30 ----------

use something like this:

while read line
do
 
VARIABLE=$(awk -F "," '{print $4}' $line)
done << file1

This is not working..

No value coming to Vriable.

i haven't told that this IS working... i haven't checked the code only the "while read ..." construct. just do a "set -xv" in your code and debug it at runtime... i'm not familar with awk, so there can be the problem...

Hi sam:

My understanding on your question is
you want to display the 4th column in that file if that was your ques then

awk '{print $4}' <filename>

the above code will work...
am sorry if i hav mistook your ques

---------- Post updated at 10:12 PM ---------- Previous update was at 10:05 PM ----------

sam:

my understanding about ur problem could be your $line is not given within quotes...
modified code should be
VARIABLE=`echo "$line"|awk -F "," '{print $4}'`
let us know if it works

Regards,
Vivek

cat file1|while read line
do
        VARIABLE=`echo "${line}"|awk -F\, '{print $4}'`
        echo "${VARIABLE}"
done

./scriptname

abvc ****
knht ****

it is working thanx know d unknown:b::o