Sponsored Content
Top Forums Shell Programming and Scripting OR operator syntax question in AWK script Post 302415987 by cgkmal on Saturday 24th of April 2010 05:42:32 AM
Old 04-24-2010
OR operator syntax question in AWK script

Hi guys,

I confused about syntax used in OR script as follow:

I have this sample file separated by "|" containing:

Code:
January|Month No. 1
February|Month No. 2
March|Month No. 3
April|Month No. 4
May|Month No. 5
June|Month No. 6
July|Month No. 7
August|Month No. 8
September|Month No. 9
October|Month No. 10
November|Month No. 11
December|Month No. 12

And I´m excluding 6 lines containing the first 6 months with this awk script (and works fine):
Code:
awk 'BEGIN {OFS=FS="|"; IGNORECASE=1} $1 !~ /january|february|march|april|may|june/' file

July|Month No. 7
August|Month No. 8
September|Month No. 9
October|Month No. 10
November|Month No. 11
December|Month No. 12

The problem is when I try to write the same one-line command in 2 or more lines, because I get errors, I mean:
Code:
awk 'BEGIN {OFS=FS="|"; IGNORECASE=1} $1 !~ /january|february|
march|april|may|june/' file

awk: BEGIN {OFS=FS="|"; IGNORECASE=1} $1 !~ /january
awk:                                         ^ unterminated regexp
awk: cmd. line:1: |february|march|april|may|june/
awk: cmd. line:1: ^ syntax error


What I´m doing wrong? how can I fix it?

* I try to do this because in the real file I need to exclude more than 20 patterns from a column and the one-line command becomes too long.

Any help would be appreciated.

Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk syntax question

Hi there could someone explain what is happening in the following function/statement for me, im just a little confused code = 'BEGIN{FS=","} { printf ("%-11s,%s%s%s,%07.2f,%14s,%-3s\n",$1,substr($2,9,2),substr($2,6,2),substr($ 2,3,2),$9,$10,$12) } this function is called later in the... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

2. Shell Programming and Scripting

yet another awk field syntax question

I am trying to print the remaing fields and field numbers beginning with a field 'xyz' #cat abc test1:test2:xyz:test3:test4:test5 #cat def test1:test2:test3:xyz:test4:test5 desired output is to be able to print NF and any trailing fields separated by':' test3 3 or test4 3 or test5... (4 Replies)
Discussion started by: prkfriryce
4 Replies

3. UNIX for Dummies Questions & Answers

AWK syntax question

Hi, Have to check file names in some given directory. SO, What is the right syntax here: *$3*=="'$object_list'" - just wanted to check if $3 is in the object_list. And also, Do I need so many quotes around? (5 Replies)
Discussion started by: Leo_NN
5 Replies

4. Shell Programming and Scripting

syntax error: `-a' unexpected operator/operand in IF

When i tyr this, it gives me a syntax error...i tried removing quotes,removing spaces,replacing -eq with '='.. Can somebody suggest that is the problem? if ]; then (4 Replies)
Discussion started by: dba.admin2008
4 Replies

5. Shell Programming and Scripting

syntax error in shell test: unknown operator

Hi All, can some one figure out the syntax issue here. How to overcome this? #!/bin/sh $ HFR_MAIL=NO $ PRP_MAIL=NO $ MC_MAIL=NO $ if && && ]; then > echo "NO " > else > echo "YES" > fi test: unknown operator NO $ if && && ]; then > echo "NO" > else > echo "YES" >... (4 Replies)
Discussion started by: shellscripter
4 Replies

6. Shell Programming and Scripting

zsh ternary operator syntax help

Hi, Can someone give me an example of how to use zsh's ternary operator? I tried: # a=1 # c=( a ? "true" : "false" ) and got: zsh: no matches found: ? I'm running zsh 4.2 on RHEL AS 4. Thanks! Paul (1 Reply)
Discussion started by: paul99
1 Replies

7. Shell Programming and Scripting

awk syntax question

Hi I use awk command to delete the first blanc line of a file: awk '/^$/ && !f{f=1;next}1' infile > outfile can somebody please explain me what the last "1'" in !f{f=1;next}1' stands for... Thansk a lot -A (3 Replies)
Discussion started by: aoussenko
3 Replies

8. UNIX for Dummies Questions & Answers

syntax error: invalid arithmetic operator

hi, i have a bash script that i want to receive a a string from another bash file. But because the string has a dot in the middle it gives me an error. The error is in this line: let valor=$1 and the value passed is rules.txt the error is: let: valor=rules.txt: syntax error: invalid... (2 Replies)
Discussion started by: limadario
2 Replies

9. Shell Programming and Scripting

syntax question in regards to nested awk statements

Hello all, I am writing up an input file and I was hoping I could get some guidance as to how to best consolidate these 2 awk statements for 1 while loop. Here's my input file # cat databases.lst #NOTE: These entries are delimited by tabs "\t" #oracleSID name/pass # db11 ... (2 Replies)
Discussion started by: Keepcase
2 Replies

10. Shell Programming and Scripting

Getting syntax error with awk ternary operator

split($7,a," "); date = a; time = a split(date,d,"/"); month = sprintf("%02d",d); day = sprintf("%02d",d); year = 2000 + d % 100 split(time,t,":"); hour=t; min=t hour >= 12? { hour=hour-12; amPm=" PM" } : amPM=" AM" hour == 0? hour=12 time=sprintf("%02d",hour)":"sprintf("%02d",min)amPm ... (4 Replies)
Discussion started by: Michael Stora
4 Replies
TIME_FIELDS_FROM_FILETIME(3)				       http://www.synce.org/				      TIME_FIELDS_FROM_FILETIME(3)

NAME
time_fields_from_filetime - convert between FILETIME and TIME_FIELDS SYNOPSIS
#include <synce.h> void time_fields_from_filetime(const FILETIME *filetime, TIME_FIELDS *timeFields); bool time_fields_to_filetime(const TIME_FIELDS *timeFields, const FILETIME *filetime); DESCRIPTION
The time_fields_from_filetime() function converts a FILETIME value into the existing broken down TIME_FIELDS struct pointed to by time- Fields. time_fields_to_filetime() does the reverse. typedef struct _TIME_FIELDS { CSHORT Year; /* Specifies a value from 1601 on. */ CSHORT Month; /* Specifies a value from 1 to 12. */ CSHORT Day; /* Specifies a value from 1 to 31. */ CSHORT Hour; /* Specifies a value from 0 to 23. */ CSHORT Minute; /* Specifies a value from 0 to 59. */ CSHORT Second; /* Specifies a value from 0 to 59. */ CSHORT Milliseconds; /* Specifies a value from 0 to 999. */ CSHORT Weekday; /* Specifies a value from 0 to 6 (Sunday to Saturday). */ } TIME_FIELDS; RETURN VALUE
The time_fields_to_filetime() function returns FALSE on encountering an invalid value, or TRUE if successful. SEE ALSO
synce(7) The SynCE Project 2007-08-26 TIME_FIELDS_FROM_FILETIME(3)
All times are GMT -4. The time now is 05:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy