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
MB_STRRPOS(3)								 1							     MB_STRRPOS(3)

mb_strrpos - Find position of last occurrence of a string in a string

SYNOPSIS
int mb_strrpos (string $haystack, string $needle, [int $offset], [string $encoding = mb_internal_encoding()]) DESCRIPTION
Performs a multibyte safe strrpos(3) operation based on the number of characters. $needle position is counted from the beginning of $haystack. First character's position is 0. Second character position is 1. PARAMETERS
o $haystack - The string being checked, for the last occurrence of $needle o $needle - The string to find in $haystack. o $offset - May be specified to begin searching an arbitrary number of characters into the string. Negative values will stop searching at an arbitrary point prior to the end of the string. o $encoding -The $encoding parameter is the character encoding. If it is omitted, the internal character encoding value will be used. RETURN VALUES
Returns the numeric position of the last occurrence of $needle in the $haystack string. If $needle is not found, it returns FALSE. CHANGELOG
+--------+---------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------+ | 5.2.0 | | | | | | | Added the optional parameter $offset. | | | | +--------+---------------------------------------+ NOTES
Note The $encoding parameter was moved from the third position to the fourth in PHP 5.2.0. For backward compatibility, $encoding can be specified as the third parameter, but doing so is deprecated and will be removed in the future. SEE ALSO
mb_strpos(3), mb_internal_encoding(3), strrpos(3). PHP Documentation Group MB_STRRPOS(3)
All times are GMT -4. The time now is 05:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy