Gawk filter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gawk filter
# 8  
Old 06-10-2010
Now u give a date 5-3-2009. But i want that the user can give a input date and the awk filter runs that date.
# 9  
Old 06-10-2010
Replace the hardcoded date with the variable user input was read into.
# 10  
Old 06-10-2010
Something along these lines should work in gawk (though I am using nawk here - but might help with the concepts):

Code:
#  nawk '
#0 setup
BEGIN {
        # prompt user
        printf("Enter a Date: ")
}
#1 read file
FILENAME == "infile" {
        # load  into an array
        entry[$1] = $0
        next
}
#2 scan for command to exit program
$0 ~ /^(quit|[qQ]|exit|[Xx])$/ { exit }
#3 process any non-empty line
$0 != "" {
        if ( $0 in entry ) {
                # it is there  so print it
                print entry[$0]
        } else
                print $0 " not found"
}

#4 prompt user again for another term
{
        printf("Enter another Date (q to quit): ")
}' infile -

HTH
# 11  
Old 06-10-2010


---------- Post updated at 05:24 AM ---------- Previous update was at 05:23 AM ----------

Quote:
Originally Posted by Tytalus
Something along these lines should work in gawk (though I am using nawk here - but might help with the concepts):

Code:
#  nawk '
#0 setup
BEGIN {
        # prompt user
        printf("Enter a Date: ")
}
#1 read file
FILENAME == "infile" {
        # load  into an array
        entry[$1] = $0
        next
}
#2 scan for command to exit program
$0 ~ /^(quit|[qQ]|exit|[Xx])$/ { exit }
#3 process any non-empty line
$0 != "" {
        if ( $0 in entry ) {
                # it is there  so print it
                print entry[$0]
        } else
                print $0 " not found"
}

#4 prompt user again for another term
{
        printf("Enter another Date (q to quit): ")
}' infile -

HTH
Il try

---------- Post updated at 05:51 AM ---------- Previous update was at 05:24 AM ----------

Well im still wondering how i get that script in a .bat file working under Gawk.

Last edited by Pow3R; 06-10-2010 at 07:29 AM..
# 12  
Old 06-10-2010
Try,

Code:
gawk -f filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gawk and regexp

Hello, This is a problem I've worked on a while and can't figure out. There is a file.txt ..some stuff.. ] ] ..some stuff.. The Awk program is trying to extract the year portion of the birth and death ("98: and "2nd C.") using the below technique #!/bin/awk @include... (5 Replies)
Discussion started by: Mid Ocean
5 Replies

2. UNIX for Dummies Questions & Answers

Filter records in a huge text file from a filter text file

Hi Folks, I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file. bash scripting is what i need. Data.txt Name OrderID Quantity Sam 123 300 Jay 342 498 Kev 78 2500 Sam 420 50 Vic 10... (3 Replies)
Discussion started by: tech_frk
3 Replies

3. SCO

Need help with gawk

I am trying to use gawk to search a file and put the second value of the string into a string. gawk -F: '$1~/CXFR/ {print $2}' go.dat Below is the file 'go.dat' ==================== HOME :/ CTMP :/tmp CUTL :/u/rdiiulio/bin CWRK :/u/work CXFR :/u/xfer ... (1 Reply)
Discussion started by: trolley
1 Replies

4. Shell Programming and Scripting

Increment Gawk

Hi, I have a small query with gawk which i'm unsure how to solve. My csv input data is as follows: 1 58352.9 34549 -469.323 LINE_149 2 58352.9 34499 -469.323 LINE_149 3 58352.9 34549 -469.323 LINE_151 4 58352.9 34503.4 -489.841 LINE_151 5 58352.9 34549 -469.323 LINE_152 6 58352.9... (1 Reply)
Discussion started by: theflamingmoe
1 Replies

5. Shell Programming and Scripting

Doubt with gawk

Hi All, I have a doubt with gawk. I have a shell script "cleanup" which calls a gawk script "cleanawk" in it. we have two unix servers epsun532 and wpsun712. So i tested the script in both the environments. In epsun532 while calling the gawk script i just mentioned something like this ... (1 Reply)
Discussion started by: Diddy
1 Replies

6. Shell Programming and Scripting

Help with gawk command

Hi, I have a situation. in a particular file , from the 9th column i have to match a particular pattern . i want a second file which is made by excluding them. I wrote a code like this. gawk '$9~/^(SPI|OTC|SAX)$/' /home/ceh1/ceh_prod/plx_"$mydate"_old.tsv >>... (1 Reply)
Discussion started by: pranabrana
1 Replies

7. Shell Programming and Scripting

Gawk Help

Hi, I am using the script to print the portion of the file containing a particular string. But it is giving error "For Reading (No such file or directory). I am using cygwin as unix simulator. cat TT35*.log | gawk -v search="12345678" ' /mSOriginating /,/disconnectingParty/ { ... (1 Reply)
Discussion started by: vanand420
1 Replies

8. Shell Programming and Scripting

gawk and bash

Hi. I'm having trouble using gawk within a bash script and I can't figure out why. I have a command that takes in a data file with two columns, the first one numbers and the second words. My code takes each line, and prints the word its corresponding number of times. The code works from the... (2 Replies)
Discussion started by: cdislater
2 Replies

9. Shell Programming and Scripting

gawk will work or not ?

Hai I am using bash-2.03$ bash --version GNU bash, version 2.03.0(1)-release (sparc-sun-solaris) I am not able to use gawk command its showing command not found , why ? Eg: awk 'NR==1' fix.txt | gawk 'BEGIN { FIELDWIDTHS = "3 2" } { printf($1"|"$2); }'... (3 Replies)
Discussion started by: tkbharani
3 Replies

10. Shell Programming and Scripting

gawk HELP

I have to compare records in two files. It can be done using gawk/awk but i am unable to do it. Please help me File1 ABAAAAAB BC asa sa ABAAABAA BC bsa sm ABBBBAAA BC bxz sa ABAAABAB BC csa sa ABAAAAAA BC dsa sm ABBBBAAB BC dxz sa File 2 ABAAAAAB BC aas ba ABAAAAAB BC asa sa... (6 Replies)
Discussion started by: sandeep_hi
6 Replies
Login or Register to Ask a Question