Problem with special characters....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with special characters....
# 1  
Old 02-25-2013
Problem with special characters....

Code:
Code:
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 proper o/p

Code:
Code:
grep -i "ADESH,id2_1_\*,airtel" COMBO_JUNK|awk -F, '
  {
    C4+=$4
  }
  {
  }
  END {
    print C4
  }
' OFS=,

Code:
Code:
here $line is ADESH,id2_1_\*

i have escape the meaninf of * by giving \.

---------- Post updated at 09:52 AM ---------- Previous update was at 09:49 AM ----------

Code:
Code:
while read line
do
while read opline
do
var=`grep -i "$line,$opline" COMBO_JUNK|awk -F, '
  {
    C4+=$4
  }
  {
  }
  END {
    print C4
  }
' OFS=,`
if [ "$var" ]
then
echo ",$var" >> hope_$opline
else
var=0
echo ",$var" >> hope_$opline
fi
done<operator.txt
done<pcstates.txt


pcstates.txt

Code:
Code:
ADESH,id1_0
ADESH,id2_1_\*
ADESH,id2_2
ADESH,id2_3
ADESH,id2_5
ADESH,id2_7
ADESH,id3_2_\*
ADESH,id3_3
ADESH,id4_2
ADESH,id4_3
ADESH,id4_4
ADESH,id4_5
ADESH,id4_6
ADESH,id4_7
ADESH,id4_8
ADESH,id4_9
ADESH,id4_10
ADESH,id5_1_\*

operator.txt

Code:
Code:
AIL
AIEL
DOMO
VONE

# 2  
Old 02-25-2013
The escaping may be too many. Pls post an execution log (reduced to the meaningful lines) using the -x option in the script.
# 3  
Old 02-25-2013
let me make the question simpler...


if i execute below command in prompt then it executes fine...
i get the o/p


Code:
Code:
grep -i "$line,$opline" COMBO_JUNK|awk -F, '
  {
    C4+=$4
  }
  {
  }
  END {
    print C4
  }
' OFS=,

but when i run it in the script...
it is not substituting $line,$opline properly

Execution logs

Code:
Code:
++ grep -i AADESH,id1_0,AELA COMBO_JUNK
++ awk -F, '
  {
    C4+=$4
  }
  {
  }
  END {
    print C4
  }
' OFS=,
+ var=43
+ '[' 43 ']'
+ echo ,43
+ read opline
++ grep -i AADESH,id1_0,AEL COMBO_JUNK
++ awk -F, '
  {
    C4+=$4
  }
  {
  }
  END {
    print C4
  }
' OFS=,
+ var=1790
+ '[' 1790 ']'
+ echo ,1790
+ read opline
++ grep -i AADESH,id1_0,DOMO COMBO_JUNK
++ awk -F, '
  {
    C4+=$4
  }
  {
  }
  END {
    print C4
  }
' OFS=,
+ var=82
+ '[' 82 ']'
+ echo ,82
+ read opline
++ grep -i AADESH,id1_0,VONE COMBO_JUNK
++ awk -F, '
  {
    C4+=$4
  }
  {
  }
  END {
    print C4
  }
' OFS=,
+ var=309
+ '[' 309 ']'
+ echo ,309
+ read opline
+ read line
+ read opline
++ grep -i 'AADESH,id2_1_*,AELA' COMBO_JUNK
++ awk -F, '
  {
    C4+=$4
  }
  {
  }
  END {
    print C4
  }
' OFS=,
+ var=
+ '[' '' ']'
+ var=0
+ echo ,0
+ read opline
++ grep -i 'AADESH,id2_1_*,AEL' COMBO_JUNK
++ awk -F, '
  {
    C4+=$4
  }
  {
  }
  END {
    print C4
  }
' OFS=,
+ var=
+ '[' '' ']'
+ var=0
+ echo ,0
+ read opline
++ grep -i 'AADESH,id2_1_*,DOMO' COMBO_JUNK
++ awk -F, '
  {
    C4+=$4
  }
  {
  }
  END {
    print C4
  }
' OFS=,
+ var=
+ '[' '' ']'
+ var=0
+ echo ,0
+ read opline
++ grep -i 'AADESH,id2_1_*,VONE' COMBO_JUNK
++ awk -F, '
  {
    C4+=$4
  }
  {
  }
  END {
    print C4
  }
' OFS=,
+ var=
+ '[' '' ']'
+ var=0
+ echo ,0
+ read opline
+ read line
+ read opline
++ grep -i AADESH,id2_2,AELA COMBO_JUNK
++ awk -F, '

# 4  
Old 02-25-2013
Et voila - there you are:
Quote:
Code:
grep -i 'AADESH,id2_1_*,AELA' COMBO_JUNK

It is looking for strings with 0 to n occurrences of _, not \*, which was what you intended. So - it's not an escape too many, but one too few.

btw - when mentioning "meaningful lines" I was talking of those around the occurrence of the problem.
btw2 - indenting and pretty printing like you do in your awk program usually is good practice, but in this simple case a one liner might be easier to read and handle: awk -F, '{C4+=$4} END {print C4}' will do!

Last edited by RudiC; 02-25-2013 at 05:47 AM.. Reason: two btw addenda
# 5  
Old 02-25-2013
thanks RUDI... i fixed it....

i used

id2_1_\\\* instead of id2_1_\*

thanks for ur reply... Smilie
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 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. Shell Programming and Scripting

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... (6 Replies)
Discussion started by: sam25
6 Replies

8. 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

9. Shell Programming and Scripting

unescaping special characters

how do i unescape special characters in Unix. Suppose i've a file named -xyz.txt, how do I remove the file. Ofcourse Icant give rm -xyz.txt thats not gonna work. We can go in regular expression like this ls | grep -e '-'xyz.txt | rm; but I'd like to know any simpler way than this. Thanks... (3 Replies)
Discussion started by: sriram_r
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