Sponsored Content
Top Forums Shell Programming and Scripting Problems with reg.-expressions in a awk-search-pattern Post 302808323 by IMPe on Thursday 16th of May 2013 12:32:04 PM
Old 05-16-2013
Problems with reg.-expressions in a awk-search-pattern

Hi,

i have some problems with regular expressions in a awk search pattern.

what i want to do:
i want to calculate the mean-value in the time from 00:00 to 06:00

how my data looks like:
Code:
....
04/01/13-01:40  670992  54802   80711   116460  156177  
04/01/13-01:50  703725  60150   85498   118844  154391  
04/01/13-02:00  639716  54841   79710   112262  153321
.....

what i tried so far:
i use the timestamp 04/01/13-hh:mm to filter my calculation.
the calc of the mean over the whole day works fine with
Code:
awk \04/01/13\ '{a+=$2} END{print a/NF}' file.txt

but when i try to extend the pattern like ..
Code:
awk \04/01/13-0[0-5]\ '{a+=$2} END{print a/NF}' file.txt

awk will crash.
can someone give me a hint please.

Thanks in advance!
IMPe

Last edited by Scrutinizer; 05-16-2013 at 02:00 PM.. Reason: extra code tags for data sample
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

SCO vs Linux Reg Expressions Problem

Hi there, I'm investigating migrating a system currently running Scos osr5 to Linux (eg RH 7.2) but there are a lot of in house scripts, some of which are probably using "Sco specific" constructs etc. One I have come across is as follows, if ????? ] then ....etc.etc fi The regular... (2 Replies)
Discussion started by: pcs7088
2 Replies

2. Shell Programming and Scripting

Problems with regular expressions

Hi , I am reading data from a log file. The log file will be like this : 19:40:25 DEBUG : Failed xml-common.noarch 0-0.6.3-18 - u 19:40:25 ERROR : Batch failed 19:40:25 DEBUG : Batch exited with ERROR 104 19:40:25 ERROR : Batch exited with ERROR 105 19:40:25 DEBUG : Batch exited... (5 Replies)
Discussion started by: subin_bala
5 Replies

3. Shell Programming and Scripting

awk search pattern

Hi, I have a log file which contains lines like below: 2010-07-19 07:13:19,021 ERROR system ...(text) 2010-07-19 07:22:03,427 ERROR system ...(text) class com... (text) 2010-07-19 07:23:19,026 ERROR system ...(text) class com... (text) each line is a separate line... I am given the a... (14 Replies)
Discussion started by: a27wang
14 Replies

4. Shell Programming and Scripting

Reg expressions

Hi, I would like to grep for a string within a tag, can someone provide some assistance in how to do it? So I would like to use the grep command to find a string like: <tag>sometext<tag> because the sometext can be any number of characters or an type of number or lettering, what expression... (1 Reply)
Discussion started by: cyberfrog
1 Replies

5. Shell Programming and Scripting

Pattern Search using AWK

Hi All, I have the below file data.txt.Using awk i want to grep all the zone data.Form the below command i can extact data upto of zone i give but i want it should print until next pattern. awk '/^Total Collection /{c=5;next}c-->0' zin45srs08.tools_utilization instead of c=5 is it possible... (5 Replies)
Discussion started by: ajaincv
5 Replies

6. UNIX for Dummies Questions & Answers

Pattern search using awk

Hi All, I am trying to find numbers with balance greater than 1 and less than equal 2 from the below file using awk Input file num ,bal 100199,1.708 100225,0 100226,0 100228,0.771166 100232,2 output file 100199,1.708 100232,2 I am using the following command for this... (2 Replies)
Discussion started by: pistachio
2 Replies

7. Shell Programming and Scripting

Awk to match a pattern and perform a search after the first pattern

Hello Guyz I have been following this forum for a while and the solutions provided are super useful. I currently have a scenario where i need to search for a pattern and start searching by keeping the first pattern as a baseline ABC DEF LMN EFG HIJ LMN OPQ In the above text i need to... (8 Replies)
Discussion started by: RickCharles
8 Replies

8. Shell Programming and Scripting

Bash script - coloring reg. expressions in text

Hi all, is there anyone good at bash who will help me? I need to use syntax ${string/pattern/replacement} The problematic part where I am stuck is: #!bin/bash text="A cat is on a mat." exp="cat" newexp="SOMECODEcatSOMECODE" newtext=${${text}/${exp}/${newexp}} == > ERROR "wrong... (4 Replies)
Discussion started by: JohnnyM77
4 Replies

9. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

10. Shell Programming and Scripting

Going mad on an egrep command (Reg Expressions)

Dear community, I am trying for several hours now to create an egrep command to grep the number of lines containing a specific text from a text-file but seem to have an error somewhere. The Textfile contains several thousand lines and has the expression "Lastname" in several lines.... (3 Replies)
Discussion started by: Donzo
3 Replies
FNMATCH(3)						   BSD Library Functions Manual 						FNMATCH(3)

NAME
fnmatch -- test whether a filename or pathname matches a shell-style pattern LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <fnmatch.h> int fnmatch(const char *pattern, const char *string, int flags); DESCRIPTION
The fnmatch() function matches patterns according to the rules used by the shell. It checks the string specified by the string argument to see if it matches the pattern specified by the pattern argument. The flags argument modifies the interpretation of pattern and string. The value of flags is the bitwise inclusive OR of any of the following constants, which are defined in the include file <fnmatch.h>. FNM_NOESCAPE Normally, every occurrence of a backslash ('') followed by a character in pattern is replaced by that character. This is done to negate any special meaning for the character. If the FNM_NOESCAPE flag is set, a backslash character is treated as an ordi- nary character. FNM_PATHNAME Slash characters in string must be explicitly matched by slashes in pattern. If this flag is not set, then slashes are treated as regular characters. FNM_PERIOD Leading periods in string must be explicitly matched by periods in pattern. If this flag is not set, then leading periods are treated as regular characters. The definition of ``leading'' is related to the specification of FNM_PATHNAME. A period is always ``leading'' if it is the first character in string. Additionally, if FNM_PATHNAME is set, a period is leading if it immediately follows a slash. FNM_LEADING_DIR Ignore ``/*'' rest after successful pattern matching. FNM_CASEFOLD Ignore case distinctions in both the pattern and the string. RETURN VALUES
The fnmatch() function returns zero if string matches the pattern specified by pattern, otherwise, it returns the value FNM_NOMATCH. SEE ALSO
sh(1), glob(3), regex(3) STANDARDS
The current implementation of the fnmatch() function does not conform to IEEE Std 1003.2 (``POSIX.2''). Collating symbol expressions, equiv- alence class expressions and character class expressions are not supported. HISTORY
The fnmatch() function first appeared in 4.4BSD. BUGS
The pattern '*' matches the empty string, even if FNM_PATHNAME is specified. BSD
July 18, 2004 BSD
All times are GMT -4. The time now is 02:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy