Sponsored Content
Full Discussion: awk searching
Top Forums Shell Programming and Scripting awk searching Post 302426747 by durden_tyler on Wednesday 2nd of June 2010 07:09:37 PM
Old 06-02-2010
Quote:
Originally Posted by manzi
...
hi all
unexpected results..
i extract the file info is very extense.... the strings exits in the file but have 3 or 4 characters

example
1268
368

try the easy example
Code:
awk -F, '$12~/68$/  {print}' 20100525*

the result is root Prompt >
...
Well, can you cut/paste the portion of your file that you expect to be captured by the awk script ?

The awk one-liner works well with my test files.

Code:
$ 
$ 
$ # how many files have names starting with "20100525" ?
$ ls -1 20100525*
20100525_myfile1.txt
20100525_myfile2.txt
$ 
$ 
$ # show the contents of both these files
$ cat 20100525_myfile1.txt
1,2,3,4,5,6,7,8,9,10,11,1267,13,14
1,2,3,4,5,6,7,8,9,10,11,1268,13,14
1,2,3,4,5,6,7,8,9,10,11,1269,13,14
$ 
$ cat 20100525_myfile2.txt
1,2,3,4,5,6,7,8,9,10,11,367,13,14
1,2,3,4,5,6,7,8,9,10,11,368,13,14
1,2,3,4,5,6,7,8,9,10,11,369,13,14
$ 
$ # now run the awk one-liner on these files
$ awk -F, '$12~/68$/  {print}' 20100525*
1,2,3,4,5,6,7,8,9,10,11,1268,13,14
1,2,3,4,5,6,7,8,9,10,11,368,13,14
$ 
$ # the result is as expected
$

Just a thought - maybe you have white space at the end of the 12th field, after "68" and before the 12th comma ?

Code:
$ 
$ cat 20100525_myfile2.txt
1,2,3,4,5,6,7,8,9,10,11,367,13,14
1,2,3,4,5,6,7,8,9,10,11,368  ,13,14
1,2,3,4,5,6,7,8,9,10,11,369,13,14
$ 
$ awk -F, '$12~/68$/  {print}' 20100525_myfile2.txt
$ 
$ # doesn't work
$ # so try this
$ awk -F, '$12~/68 *$/  {print}' 20100525_myfile2.txt
1,2,3,4,5,6,7,8,9,10,11,368  ,13,14
$ 
$


HTH,
tyler_durden
This User Gave Thanks to durden_tyler For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching for + sign in a string using awk

Hi All, My query is: I have string say xyz+ how to determine that whether it ends with a + sign or not using awk command. (5 Replies)
Discussion started by: satyajit2512
5 Replies

2. Shell Programming and Scripting

awk searching between two files

hi there, im writing some script in awk; in few words i have a list from router (mac address- ip address) and the second list with only the mac addresses. the thing is that i want search list from router for the first mac address; if found - print the ip address, if not print error; then search... (1 Reply)
Discussion started by: mac7
1 Replies

3. Shell Programming and Scripting

Searching word in a file with awk

Hello everyone! I use a script to query for installed packages with yum (I use RHEL 4 with yum installed) and the output is redirected to a file. My script scan this file to find a package and the version of it. The script works fine until I search for a package name with special characters.... (3 Replies)
Discussion started by: studieu
3 Replies

4. Shell Programming and Scripting

awk and searching within a block ?

Hi, I wonder if anybody could help. How do i awk out (or indeed using another utility) a particular value that exists within a defined block, for example if i have a file that looks like the one below and i want to get at the "Product Serial" for the block referring to "mb.fru" (bolded and coloured... (4 Replies)
Discussion started by: rethink
4 Replies

5. Shell Programming and Scripting

Searching using awk - Help required

Hi... I am working on script to search some records in a file based on certain fields and each record is a ASCII fixed size. I was using awk to search based on certain condition. But the length of the record is too much that awk is giving syntax error near unexpected token `(' Request... (5 Replies)
Discussion started by: ysrikanth
5 Replies

6. Shell Programming and Scripting

Searching a file using awk or sed

I want to search a file in a specific location and I don't want to use find command. I want to give the path also where the file is for searching it. Pls help (3 Replies)
Discussion started by: maitree
3 Replies

7. Shell Programming and Scripting

awk: searching for non-breaking-space

This code shal search for the non-breaking space 0xA0 though it returns the error "fatal: attempt to use scalar 'nbs' as array" Can somebody help? awk --non-decimal-data -v nbs="0xA0" '{if($0 in nbs) {print FILENAME, NR}}' *.txt (1 Reply)
Discussion started by: sdf
1 Replies

8. Shell Programming and Scripting

Searching multiple patterns using awk

Hello, I have the following input file: qh1adm 20130710111201 : tp import all QH1 u6 -Dsourcesystems=BFI,EBJ qh1adm 20130711151154 : tp import all QH1 u6 -Dsourcesystems=BFI,EBJ qx1adm 20130711151154 : tp count QX1 u6 -Dsourcesystems=B17,E17,EE7 qh1adm 20130711151155 : tp import all... (7 Replies)
Discussion started by: kcboy
7 Replies

9. Shell Programming and Scripting

Searching value in table through awk

I need to create one script in which I want to search in txt file , this txt file is having 10 columns , I want to check 4th column value if "BOY" & 10th column value =>500 it will print 4th column row value ,1st column row value & 10th column row value & store the same value in one file as... (2 Replies)
Discussion started by: dravi_laxmi
2 Replies

10. Shell Programming and Scripting

Searching content of a variable using awk

so i'm running a variation of the following command a few times in my script: echo "${TOTALRunning}" | awk -F"" '/'"${PROCSEARCH}"'/ {print $2}' | tr '\n' '|' unfortunately i cant paste the content of the variable TOTALRunning into this thread for security reasons. what i want to do is... (9 Replies)
Discussion started by: SkySmart
9 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 06:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy