Can any good awk'er resolve this issue?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Can any good awk'er resolve this issue?
# 1  
Old 12-03-2008
Can any good awk'er resolve this issue?

awk -F^ '{ if ((($1 != "M") && ($5 != "2")) || (($1 != "S") && ($5 != "7"))) print $0}' welcome > welcome1


The "&&" and "||" in the above command is not working with awk.

When I run the above command, the same content of welcome is copied to welcome1 without any difference.

Your reply is highly appreciated.

Thanks in advance.
# 2  
Old 12-03-2008
Pls. check your if condition. For the data not to be copied the if condition should give FALSE.


Regards,
Vinod.

Quote:
Originally Posted by karthickrn
awk -F^ '{ if ((($1 != "M") && ($5 != "2")) || (($1 != "S") && ($5 != "7"))) print $0}' welcome > welcome1


The "&&" and "||" in the above command is not working with awk.

When I run the above command, the same content of welcome is copied to welcome1 without any difference.

Your reply is highly appreciated.

Thanks in advance.
# 3  
Old 12-03-2008
Nothing is happening ...the command is just redirecting the contents of welcome to welcome1 without any difference.
# 4  
Old 12-03-2008
Pls. show the contents of welcome.

Quote:
Originally Posted by karthickrn
Nothing is happening ...the command is just redirecting the contents of welcome to welcome1 without any difference.
# 5  
Old 12-03-2008
pls find below welcome content

S^E^2008^12G43^7
C^E^2008^ZAT08^14
S^E^2008^ZAR48^22
M^E^2008^0TL69^2
S^E^2008^FCB67^30
# 6  
Old 12-03-2008
The command is working fine. just added two lines to the file contents:

S^E^2008^12G43^7
C^E^2008^ZAT08^14
S^E^2008^ZAR48^22
M^E^2008^0TL69^2
S^E^2008^FCB67^30
M^hi^vi^5^7
M^E^2008^0TL69^7


Now you can see the result that the last two lines are not copied as per the if condition applied.

Regards,
Vinod.
# 7  
Old 12-03-2008
I need an o/p which does not have the one's highlighted below in red as per my command.
S^E^2008^12G43^7
C^E^2008^ZAT08^14
S^E^2008^ZAR48^22
M^E^2008^0TL69^2
S^E^2008^FCB67^30
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looking for good book on awk

I am not sure if I am posting to the right forum but I would like to buy a book which goes into Awk in detail and covers the most advanced Awk programming techniques. Would anybody be able to recommend a good book? I see plenty of books available on Amazon but I am not sure how detailed they are.... (2 Replies)
Discussion started by: kieranfoley
2 Replies

2. Solaris

Cannot resolve PTR record issue

Hi guys, I am currently receiving the following output in /var/log/syslog and is occurring every second leading to /var directory being full after every 2 days. Aug 20 17:32:29 opaldn1 sendmail: r7KCOlQm002517: ruleset=check_rcpt, arg1=<postmaster@silverapp6>, relay=, reject=450 4.4.0... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

3. Shell Programming and Scripting

Cannot resolve $variable in awk

My script ---------- for i in `cat n`;do export k=`echo "CSN: "$i` //combining CSN: and value from n echo "$k" awk ''{print "CSN: "$0;}'{_=29}_&&_--' file1|tail -1 >> file2 done In the above script i cannot able to resolve $k in awk command file n contains ------------ 0000 1111 2222... (2 Replies)
Discussion started by: Mohana29_1988
2 Replies

4. Shell Programming and Scripting

Cannot resolve $var in awk

My script ---------- for i in `cat n`;do export k=`echo "CSN: "$i` //combining CSN: and value from n echo "$k" awk ''{print "CSN: "$0;}'{_=29}_&&_--' file1|tail -1 >> file2 done In the above script i cannot able to resolve $k in awk command file n contains ------------ 0000 1111... (0 Replies)
Discussion started by: Mohana29_1988
0 Replies

5. Shell Programming and Scripting

Need awk good link

Guys, I am always struggling with awk and sed commands in UNIX,especially while writing shell script. Can you please suggest some good websites? Cheers, Aravind (3 Replies)
Discussion started by: AraR87
3 Replies

6. Shell Programming and Scripting

The awk subtraction giving exponential values.Please help resolve it

Hi friends, I have a file list1 which has these 2 columns like 616449 0 434453 1 2151083 0 2226536 0 2132382 0 2136814 0 I have to put the result of col1 -col2 into another file list2 linewise. e.g. It gives the below result if use the below code: awk '{ print $1 - $2 }' list1 >... (2 Replies)
Discussion started by: kunwar
2 Replies

7. Shell Programming and Scripting

Need assistance to resolve the KSH issue

am running the small script below. count_a=48 count_b=48 if ; then echo "Count matched" else echo "count not matched" fi I got the below output. /bin/ksh: [48: not found count not matched It was giving the same error when I ran in another box. But I inculded /bin/ksh in the... (10 Replies)
Discussion started by: sathik
10 Replies

8. Shell Programming and Scripting

Does awk ever resolve params ?..

Hi, Does awk ever resolve params in the search pattern?.. The following awk doesnt know how to resolve ${tables}$ inside a loop. k=`awk '/${tables}$/ ${graph}` The search pattern has ${tables}$ and I am narrowing down my search with a $ at the end of string. So...this leaves me with a... (13 Replies)
Discussion started by: anduzzi
13 Replies
Login or Register to Ask a Question