special characters giving problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting special characters giving problem
# 1  
Old 09-09-2009
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

Code:
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:-

Code:
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.Smilie


Please suggest.

Regards,
SAM

Last edited by DukeNuke2; 09-09-2009 at 12:31 PM.. Reason: added code tags
# 2  
Old 09-09-2009
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 [code] and [/code] 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:

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

# 3  
Old 09-09-2009
This is not working..

No value coming to Vriable.
# 4  
Old 09-09-2009
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...
# 5  
Old 09-09-2009
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
# 6  
Old 09-09-2009
Code:
cat file1|while read line
do
        VARIABLE=`echo "${line}"|awk -F\, '{print $4}'`
        echo "${VARIABLE}"
done

./scriptname

abvc ****
knht ****

# 7  
Old 09-09-2009
it is working thanx know d unknownSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with special characters....

grep -i "$line,$opline" COMBO_JUNK|awk -F, ' { C4+=$4 } { } END { print C4 } ' OFS=,` when i run this command in the script.... it o/p all the value as 0 if $line contains any special parameters..... but the same script if i run in command prompt... it shows... (4 Replies)
Discussion started by: nikhil jain
4 Replies

2. Shell Programming and Scripting

Problem with Special characters in file

Hi, I am facing a below problem. Inorder to mak sure the below file is fixed width i am using the following command awk '{printf("%-375s\n", $0) } so as to add trailing spaces at the end for records of length less than 375. Input file > inp.txt 1©1234 1234 123©1 The output file is... (1 Reply)
Discussion started by: marcus_kosaman
1 Replies

3. Shell Programming and Scripting

shell script is giving different resultControlled Special Account [csdwmast@ucdoud01.am.sony.com

Hi All, In this below script i am not able to find where is "form mail id" is taking when this script is executing i am getting "Controlled Special Account " as from ,i need to send "form mail id " from a table.:mad: kindly help me plzz. Regards, Krupa (0 Replies)
Discussion started by: krupasindhu18
0 Replies

4. Shell Programming and Scripting

script to tail file; problem with awk and special characters

Trying to use code that I found to send only new lines out of a log file by doing: while :; do temp=$(tail -1 logfile.out) awk "/$last/{p=1}p" logfile.out #pipe this to log analyzer program last="$temp" sleep 10 done Script works fine when logfile is basic text, but when it contains... (2 Replies)
Discussion started by: moo72moo
2 Replies

5. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

6. Shell Programming and Scripting

special characters

Hey guys, I'm trying to replace "]Facebook" from the text but sed 's/]Facebook/Johan/g' is not working could you please help me with that? (6 Replies)
Discussion started by: Johanni
6 Replies

7. UNIX for Dummies Questions & Answers

How to see special characters?

Hi all, I was wondering how can i see the special characters like \t, \n or anything else in a file by using Nano or any other linux command like less, more etc (6 Replies)
Discussion started by: gvj
6 Replies

8. Shell Programming and Scripting

Special characters

When I open a file in vi, I see the following characters: \302\240 Can someone explain what these characters mean. Is it ASCII format? I need to trim those characters from a file. I am doing the following: tr -d '\302\240' ---------- Post updated at 08:35 PM ---------- Previous... (1 Reply)
Discussion started by: sid1982
1 Replies

9. HP-UX

utf-8, problem with special characters

Hi all, We are facing the following problem in our HP-UX machine: software that manipulates utf-8 encoded strings (e.g. during string cut), fails to correctly manipulate strings (all containing Greek characters) that contain special characters like @, &, # etc. Actually, in different... (3 Replies)
Discussion started by: alina
3 Replies

10. UNIX for Dummies Questions & Answers

special characters

I have one file which is named ^? ( the DEL character ) I'd like to know how to rename or copy the file by using its i-node number TYIA (2 Replies)
Discussion started by: nawnaw
2 Replies
Login or Register to Ask a Question