awk - special character not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk - special character not working
# 1  
Old 06-21-2013
awk - special character not working

Hi,

I am trying to use forward slash in awk. While running the command through console, its working fine but not working while running it through shell script.

Code:
find . -name "*" -ctime -6 | xargs cat | grep -E -v ^fileName\|^\([0-9]\) | awk -v DATE="${CURR_DATE}" -v DATE_LOG="$DATE_SYS" '
        BEGIN {
                FS = ";"
                OFS = ";"
                CONVFMT = "%.9g"
                OFMT = "%.9g"
        }
        {
                clef = "2-PARSING_ERROR;" DATE ";" DATE_LOG ";"
                substr ( $0, 12, 8) ";" substr ( $0, 5, 6 ) ";NS;N/A;" $3
                tab[clef]++
        }
        END {
                for (clef in tab)
                {
                        print tab[clef],clef
                }
        }
'

Is the problem because my console shell is bash and through script it is ksh?

How to use the forward slash in awk? I tried escaping it with 2 backslashes , also quoting it but none worked.

Please help.
# 2  
Old 06-21-2013
I am not sure if I understand your problem. Which forward slash do you mean? This one in here?
Code:
";NS;N/A;"

This works when being used as part of the key in that array (at least with GNU awk).
Only thing I see missing is a backslash to fuse these two lines together:
Code:
                clef = "2-PARSING_ERROR;" DATE ";" DATE_LOG ";" \
                substr ( $0, 12, 8) ";" substr ( $0, 5, 6 ) ";NS;N/A;" $3

# 3  
Old 06-21-2013
yes this forward slash : ";NS;N/A;"

but just to show the indentation , i have split the lines like that.

But it is not working because of "N/A". how to handle this slash?
# 4  
Old 06-21-2013
As said with GNU awk it is working. What is your version of awk? What is "not working"? What is the error output you get?
Simplified example:
Code:
$ cat infile
one
two
three
$ awk '{_[$1"/"]=$1} END{for(a in _){print "Key:", a, "Value:", _[a]}}' infile
Key: three/ Value: three
Key: two/ Value: two
Key: one/ Value: one

Update:
It even works with the more limited awk on AIX.

Last edited by zaxxon; 06-21-2013 at 09:16 AM.. Reason: enhanced readability
# 5  
Old 06-21-2013
I suggest you give us some clue about input and desired output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Special character $$

Hi, on ksh What does the following do? grep -v "toolbox" $home_oracle/.profile >$home_oracle/.profile.$$ Thanks. Please use CODE tags as required by forum rules! (3 Replies)
Discussion started by: big123456
3 Replies

2. Shell Programming and Scripting

awk search for max and min while ignoring special character

I am trying to get a simple min/max script to work with the below input. Note the special character (">") within it. Script awk 'BEGIN{max=0}{if(($1)>max) max=($1)}END {print max}' awk 'BEGIN{min=0}{if(($2)<min) min=($2)}END {print min}' Input -122.2840 42.0009 -119.9950 ... (7 Replies)
Discussion started by: ncwxpanther
7 Replies

3. Shell Programming and Scripting

awk command to find total number of Special character in a column

How to find total number of special character in a column? I am using awk -f "," '$col_number "*$" {print $col_number}' file.csv|wc -l but its not giving correct output. It's giving output as 1 even though i give no special character? Please use code tags next time for your code and... (4 Replies)
Discussion started by: AjitKumar
4 Replies

4. Shell Programming and Scripting

Regex escape special character in AWK if statement

I am having issues escaping special characters in my AWK script as follows: for id in `cat file` do grep $id in file2 | awk '\ BEGIN {var=""} \ { if ( /stringwith+'|'+'50'chars/ ) { echo "do this" } else if ( /anotherString/ ) { echo "do that" } else { ... (4 Replies)
Discussion started by: purebc
4 Replies

5. UNIX for Advanced & Expert Users

awk command in special character

Hi, I want to add below line after end of a file (i.e file1) &&echo "copy done" >> out.txt cat file1 scp user1@server1:/tmp/dir /tmp/dir1 my requirment is cat file1 scp user1@server1:/tmp/dir /tmp/dir1 &&echo "copy done" >> out.txt could any one please help me (7 Replies)
Discussion started by: anshu ranjan
7 Replies

6. Shell Programming and Scripting

Deleteing one character after an special character

I have below line in a unix file, I want to delete one character after "Â". 20091020.Non-Agency CMO Daily Trade Recap Â~V Hybrids The result should be : 20091020.Non-Agency CMO Daily Trade Recap  Hybrids i dont want to use "~V" anywhere in the sed command or any other command, just remove... (1 Reply)
Discussion started by: mohsin.quazi
1 Replies

7. Shell Programming and Scripting

Awk not working due to missing new line character at last line of file

Hi, My awk program is failing. I figured out using command od -c filename that the last line of the file doesnt end with a new line character. Mine is an automated process because of this data is missing. How do i handle this? I want to append new line character at the end of last... (2 Replies)
Discussion started by: pinnacle
2 Replies

8. Shell Programming and Scripting

Special Character SED/AWK removal

I have a script that produces an output containing '/.ssh'. I am trying to find a way of parsing only this data from a single line, without removing any other special characters contained within the output as a result of the parse. Any help would be appreciated (6 Replies)
Discussion started by: Raggedranger333
6 Replies

9. Shell Programming and Scripting

special character

Hi, I am trying to unload file from a database. Which contains few lines with the character below. Rest of the data was unloaded appropriately. a) What does this below character means? b) How can i remove it, I already have sed '/^$/d' c) Will this effect the file by any means... (4 Replies)
Discussion started by: tostay2003
4 Replies

10. Shell Programming and Scripting

sub option of awk command not working with "\" character.

Hi all, I would like to replace some string in a text file by some string which would contains special characters like "/","\". I.e. I have a text file with the statement contactperson somewhere in it. Now I want to replace it by something else which includes special characters like "/","\" ... (1 Reply)
Discussion started by: shareef
1 Replies
Login or Register to Ask a Question