Sponsored Content
Top Forums Shell Programming and Scripting Awk search for string pattern in delimited file Post 302442770 by Franklin52 on Thursday 5th of August 2010 11:42:52 AM
Old 08-05-2010
Quote:
Originally Posted by alienated
Thank you for your prompt reply.

I wish to perform some additional functions in your current command. I would like to get the key and value pair.

Code:
FS="="  
split($i, MTH)
key = MTH[1]
value = MTH[2]

FS="/" # if there is no / separator, can I just check the value?
split($value, MTHCHECK)
oldmth=value[1]
newmth=value[2]
# if the value is null -z just skip the check
if oldmth > "12" print "invalid mth" 
if oldmth > "0" && < "13" print "valid mth"
if newmth> "12" print "invalid mth" 
if newmth > "0" && < "13" print "valid mth"

How do i incorporate all this into an awk command? I am using bash by the way. Thanks again.
The awk command gives the output as you desire in your first post.

Can you post the exact desired output from the given log file?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search Mulitiple String pattern in a file

Hi, I need to search for a multiple string pattern(5 key words) in a file(similar to a flat file) ,and i need to store the output in a another file . In that file we may have mutiple occurrences of the key words.and i need only the unique. kindly help out. Thanks, Mohana Krishnan (2 Replies)
Discussion started by: krishnan_6015@y
2 Replies

2. UNIX for Dummies Questions & Answers

Trim String in 3rd Column in Tab Delimited File...SED/PERL/AWK?

Hey Everybody, I am having much trouble figuring this out, as I am not really a programmer..:mad: Datafile.txt Column0 Column1 Column2 ABC DEF xxxGHI I am running using WGET on a cronjob to grab a datafile, but I need to cut the first three characters from... (6 Replies)
Discussion started by: rickdini
6 Replies

3. UNIX for Dummies Questions & Answers

Search and replace string only in a particular column in a delimited file

I have file with multiple columns. Column values for a record may be same. Now i have to replace a column value(this can be same for the other columns) with new value. File.txt A,B,C,D,A,B,C,D,A,B,C,D A,B,C,D,A,B,C,D,A,B,C,D A,B,C,D,A,B,C,D,A,B,C,D A,B,C,D,A,B,C,D,A,B,C,D... (1 Reply)
Discussion started by: ksailesh
1 Replies

4. Shell Programming and Scripting

Help needed :Search and Replace a string pattern with empty in an xml file in unix

Search and Replace a string pattern with empty in an xml file in unix: My xml file would be like this : <Accounts><Name>Harish</Name><mobile>90844444444444445999 </mobile><TRIG>srcujim-1</TRIG></Accounts><Accounts><Name>Satish</Name><mobile>908999</mobile><TRIG>ettertrtt-1</TRIG></Accounts> ... (1 Reply)
Discussion started by: harish_s_ampeo
1 Replies

5. Shell Programming and Scripting

awk get search pattern from a file.

Here Is a problem I am facing with awk. Query --> I want to search for a string in a file and print next 15 lines below the matched string. 1.We do not have GNU grep so cannot use grep -A or grep -B commands. 2. Instead of passing the search pattern as a string to awk. I want the awk to... (4 Replies)
Discussion started by: togotutor
4 Replies

6. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

7. Shell Programming and Scripting

awk read one delimited file, search another delimited file

Hello folks, I have another doozy. I have two files. The first file has four fields in it. These four fields map to different locations in my second file. What I want to do is read the master file (file 2 - 23 fields) and compare each line against each record in file 1. If I get a match in all four... (4 Replies)
Discussion started by: dagamier
4 Replies

8. Shell Programming and Scripting

How can I use find command to search string/pattern in a file recursively?

Hi, How can I use find command to search string/pattern in a file recursively? What I tried: find . -type f -exec cat {} | grep "make" \; Output: grep: find: ;: No such file or directory missing argument to `-exec' And this: find . -type f -exec cat {} \; -exec grep "make" {} \;... (12 Replies)
Discussion started by: cola
12 Replies

9. UNIX for Beginners Questions & Answers

Search a string inside a pattern matched block of a file

How to grep for searching a string within a begin and end pattern of a file. Sent from my Redmi 3S using Tapatalk (8 Replies)
Discussion started by: Baishali
8 Replies

10. 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
notifyutil(1)						    BSD General Commands Manual 					     notifyutil(1)

NAME
notifyutil -- notification command line utility SYNOPSIS
notifyutil [-q] [-v] [-z msec] [-M] [-R] [command ...] DESCRIPTION
notifyutil is a command-line utility for interacting with the notify(3) notification system and the notifyd(8) server. It may be used to post notifications, detect and report notifications, and to examine and set the state values associated with notification keys. If notifyutil is used to monitor one or more notification keys, it prints the notification key when the corresponding notification is received. The -v (verbose) and -q (quiet) flags, if specified, modify the output behavior. The -v flag causes notifyutil to print a time stamp, the notification key, the current state value for that key, and the type of the notifi- cation (port, file, etc). The -q flag supresses any output except for state values fetched following a -g command. Commands listed in the table below are processed in left to right order from the command line. -p key Post a notification for key. -w key Register for key and wait forever for notifications. -# key Register for key and wait for # (an integer) notifications. E.g. -1 key waits for a single notification. -g key Get state value for key. -s key val Set state value for key. -port Use mach port notifications for subsequent -w or -# registrations. This is the default registration type. -file Use file descriptor notifications for subsequent registrations. -check Use shared memory notifications for subsequent registrations. -signal [#] Use signal notifications for subsequent registrations. Signal 1 (HUP) is the default, but an alternate signal may be specified. -dispatch Use dispatch for subsequent registrations. When invoked with any combination of -w and -# actions, notifyutil registers for notification for the specified key(s). If any key is given with a -w action, notifyutil runs until interrupted with Control-C. If all registrations are invoked with -#, the program continues to run until the corresponding number of notifications for each key have been received. By default, notifyutil uses mach port registration (using notify_register_mach_port()) for keys given with a -w or -# flag. The -file com- mand causes notifyutil to use notify_register_file_descriptor() for any subsequent -w or -# registrations. Similarly, -check causes notifyutil to use notify_register_check() for subsequent registrations, -signal switches to notify_register_signal(), and -dispatch causes it to use notify_register_dispatch() for subsequent registrations. If any registrations are made following the use of the -check command, notifyutil will start a timer and check for shared memory notifica- tions every 100 milliseconds. An alternate timer value may be set following the -z flag. The -M flag causes notifyutil to use multiplex all notifications over a single mach connection with notifyd. Notifications (except shared memory notifications) are received and redistributed by a dispatch handler. The -R flag causes notifyutil to regenerate all its registrations in the unlikely event that notifyd restarts. Note that a notification key and its associated state variable only exist when there are one or more current registrations for that key. Setting the state for a key that has no registrations has no effect. Thus the command notifyutil -s foo.bar 123 -g foo.bar will print foo.bar 0 unless foo.bar is registered by some other process. However, the command notifyutil -w foo.bar -s foo.bar 123 -g foo.bar prints foo.bar 123 since the ``-w foo.bar'' registration ensures the key and its state variable exist before the value is set, and continue to exist when the value is fetched. SEE ALSO
notify(3), notifyd(8) Mac OS X November 4, 2011 Mac OS X
All times are GMT -4. The time now is 05:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy