small doubt in awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers small doubt in awk
# 1  
Old 06-03-2010
Bug small doubt in awk

Hi Guys,

I have a small problem with awk.

I want to search { and } at a particular position in a string using awk.

I tried

Code:
echo "hello{hi" | awk '{if(substr($0,6,1)=="{"){print "TRUE"}}'

but no success Smilie

i know it can be done in many ways and i know them also.. but my question is how can we suppress "{" in awk??

Last edited by vidyadhar85; 06-03-2010 at 01:22 PM.. Reason: typo
# 2  
Old 06-03-2010
It is working for me
Code:
$ echo "hello{hi" | awk '{if(substr($0,6,1)=="{"){print "TRUE"}}'
TRUE
$ echo "hello{hi" | awk '{if(substr($0,6,1)=="\{"){print "TRUE"}}'
TRUE

# 3  
Old 06-03-2010
Quote:
Originally Posted by anbu23
It is working for me
Code:
$ echo "hello{hi" | awk '{if(substr($0,6,1)=="{"){print "TRUE"}}'
TRUE
$ echo "hello{hi" | awk '{if(substr($0,6,1)=="\{"){print "TRUE"}}'
TRUE

which OS??
because its not working for me I am working on AIX
# 4  
Old 06-03-2010
Hi vidyadhar85

I just tried it, and it works for me too:

Code:
> oslevel -s
5300-08-04-0844

> echo "hello{hi" | awk '{if(substr($0,6,1)=="{"){print "TRUE"}}'
TRUE

# 5  
Old 06-03-2010
Hmmm strange guys..

Let me verify it once again and get back to you..

anyways thanks for your help
# 6  
Old 06-03-2010
AIX 6
# 7  
Old 06-03-2010
Quote:
Originally Posted by vidyadhar85
Hmmm strange guys..

Let me verify it once again and get back to you..

anyways thanks for your help
Strange indeed (I would imagine that to work in any awk - except Solaris probably, because that awk's rubbish Smilie).

Try cutting and pasting from here or retyping. Maybe you have a hidden character in there somewhere?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk small discussion on array

Hi...all I want to pass array name for some function using loop anyone is having idea ? here is scenario echo | awk ' BEGIN{ A1="foo1" A2="foo2" A3="foo3" } function test1(a,b,c){ print a,b,c ... (10 Replies)
Discussion started by: Akshay Hegde
10 Replies

2. UNIX for Dummies Questions & Answers

a doubt in awk

instead of writing print command in awk, i saw in some posts that we can simply write a number before we end the awk command and it will print the file. As given below: $awk '{some manipulation; print}' filename $awk '{some manipulation}1' filename I also tried replacing the... (2 Replies)
Discussion started by: PranavEcstasy
2 Replies

3. Shell Programming and Scripting

Small doubt for using wget cia SSH!!!

Hi Guys, I have just ran into a small problem where I am trying to ssh to another server and the script does a wget on that server. Following is the syntax I am using though it's not working as expected. A normall wget on the local system simply shows the verbose output in one horizontal line... (2 Replies)
Discussion started by: rockf1bull
2 Replies

4. AIX

Small doubt on xterm

My manager asked me to do xterm the particular server...I tried as below..getting permission denied. I asked my manager same...he suggesting you need to setup a profile..i'm not sure what he is talking about. $ xterm -display 136.151.221.212:0.0 -sb -sl 1000 & 30076 $ ksh: xterm:... (1 Reply)
Discussion started by: RajChow
1 Replies

5. Shell Programming and Scripting

Awk doubt

I have a file sample.txt with the following contents: the following gives output as awk 'NF{s=$0; print s}' sample.txt but, awk 'NF{s=$0}{print s}' sample.txtgives output as why this difference, can someone explain me? (6 Replies)
Discussion started by: royalibrahim
6 Replies

6. Solaris

small doubt reg uname command

Am new to solaris can anyone explain the fields in the below command. Also let me know the difference between nodename and hostname. Here osnask2 is the hostname and type SUNOS. What abt the remaining fields.? #uname -a SunOS osnska2 5.8 Generic_117350-47 sun4u sparc SUNW,Sun-Fire-480R (1 Reply)
Discussion started by: rogerben
1 Replies

7. UNIX for Dummies Questions & Answers

A small AWK problem

I have a file tmp.out with contents: 2008-08-09 05:11:01 2008-08-09 08:52:59 2008-08-11 12:08:34 2008-08-11 12:15:40 I want the output to be: 3|0|1|71|2008-08-09 05:11:01|2008-08-30 11:19:28 4|0|1|71|2008-08-09 08:52:59|2008-08-30 11:19:28 5|0|1|71|2008-08-11 12:08:34|2008-08-30 11:19:28... (6 Replies)
Discussion started by: ChicagoBlues
6 Replies

8. Shell Programming and Scripting

doubt on awk

I have executed the below command: find . -name "Ks*" -type f -exec ls -ltr {} \; | awk '{printf("%ld %s %d %s \n",$5,$6,$7,$8,$9)}' and here is the output: 1282 Oct 7 2004 51590 Jul 10 2006 921 Oct 7 2004 1389 Jun 4 2003 1037 May 19 2004 334 Mar 24 2004 672 Jul 8 2003 977... (6 Replies)
Discussion started by: venkatesht
6 Replies

9. Shell Programming and Scripting

awk doubt..

Hello, Iam trying to get the IP of the hostname of the machine from /etc/hosts. I used the command as below: But the result shows the IP with the hostname.. like 192.168.0.8 test12111.com I need to get only 192.168.0.8 Please help Thanks in advance esham (11 Replies)
Discussion started by: esham
11 Replies

10. UNIX for Dummies Questions & Answers

awk doubt

I'm having a file with 5 fields. I want to sort that file according to one field no 3. How shall I do using awk programming. Any input appreciatable. regards, vadivel. (7 Replies)
Discussion started by: vadivel
7 Replies
Login or Register to Ask a Question