Sponsored Content
Top Forums Shell Programming and Scripting passing a regex as variable to awk and using that as regular expression for search Post 302599168 by Corona688 on Thursday 16th of February 2012 11:01:00 AM
Old 02-16-2012
That's a slight fallacy known as useless use of ls *, it's not ls that understands what * means -- it's the shell itself. That's why * works the same way with every command.

mput is independent of the shell however, and does its own processing of *, but it works the same way as the shell.

You're going to need to modify your shell script I think. Perhaps you can tell it the prefix you want, instead of giving it the entire "abc*.dat", and the shell can replace that itself, and you can feed that into awk in the form you want as well.

To modify your shell script I'll need to actually see it of course.

---------- Post updated at 10:01 AM ---------- Previous update was at 09:55 AM ----------

This kludge might also work, but it's not pretty. It replaces all . by \., all * by .*, prepends ^, and appends $ to turn simple globs into regular expressions. If your awk doesn't have gsub, use nawk.

Code:
awk -v STR="*.dat" 'BEGIN { gsub(/[.]/, "\\.", STR); gsub(/[*]/, ".*", STR); STR="^" STR "$" }; /^-/ && ($9 ~ STR) { print $9 "|" $5 }'

This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk's variable in regular expression

Anyone know how I will use awk's variable in a regular expression? This line of code of mine is working, the value PREMS should be a variable: awk '$1 ~ /PREMS/ { if(length(appldata)+2 >= length($1)) print $0; }' appldata=$APPLDATA /tmp/file.tmp The value of APPLDATA variable is PREMS. ... (2 Replies)
Discussion started by: Orbix
2 Replies

2. Shell Programming and Scripting

AWK - compare $0 to regular expression + variable

Hi, I have this script: awk -v va=45 '$0~va{print}' flo2 That returns: "4526745 1234 " (this is the only line of the file "flo2". However, I would like to get "va" to match the begining of the line, so that is "va" is different than 45 (eg. 67, 12 ...) I would not have any output. That... (3 Replies)
Discussion started by: jolecanard
3 Replies

3. Shell Programming and Scripting

Regular expression (regex) required

I want to block all special characters except alphanumerics.. and "."(dot ) character currently am using // I want to even block only single dot or multiple dots.. ex: . or .............. should be blocked. please provide me the reg ex. ---------- Post updated at 05:11 AM... (10 Replies)
Discussion started by: shams11
10 Replies

4. UNIX for Advanced & Expert Users

Regular expression / regex substition on Unicode text

I have a large file encoded in Unicode that I need to convert to CSV. In general, I know how to do this by regular expression substitutions using sed or Perl, but one problem I am having is that I need to put a quotation mark at the end of each line to protect the last field. The usual regex... (1 Reply)
Discussion started by: thomas.hedden
1 Replies

5. Shell Programming and Scripting

awk + pattern search with regular expression

Hi , I have a file with "|" (pipe) as a delimeter. I am looking for the record count where 5th field is a number with 15 digit length only. all the records with above requirement is valid rest all are invalid. I need count of valid records and invalid records. Can anyone please help (9 Replies)
Discussion started by: vikash_k
9 Replies

6. Shell Programming and Scripting

Passing Variable to Regular Expression

Hi All, Below is a sample code: print "Enter the Name: "; my $Name = <>; print "Word is $Name"; open (FH,"AIDNameList.txt"); while (<FH>) { my $line; print "Word is $Name"; for $line(<FH>)... (12 Replies)
Discussion started by: jisha
12 Replies

7. Shell Programming and Scripting

How can awk search a string without using regular expression?

Hello, Awk seem treat the pattern as regular expression, how can awk search not using regular expression? e.g. just represent for "", not "A" or "a" . I don't want to add backslash . (2 Replies)
Discussion started by: 915086731
2 Replies

8. Emergency UNIX and Linux Support

Regular expression (regex) clean up text

Hi, Server - MEDIAWIKI - MYSQL - CENTOS 5 - PHP5 I have a database import of close to a million pages into my wiki, mediawiki site, the format that were left with is not pretty, and I need to find a way to clean this up and present it nicely... I think regex is the best option as I can... (1 Reply)
Discussion started by: lawstudent
1 Replies

9. Shell Programming and Scripting

Passing regular expression to nawk

I am trying to test if I can replace a regular expression in 'nawk' with a variable. Please let me know why it is not working. I am using ksh88i on solaris8 I am trying use this test as a building block to filter active external DNS connections. Ideally I want to pass variable defined... (4 Replies)
Discussion started by: kchinnam
4 Replies

10. Shell Programming and Scripting

awk regular expression search

Hi All, I would like to search a regular expression by passing as an i/p variableto AWK. For Example :: 162.111.101.209.9516 162.111.101.209.41891 162.111.101.209.9516 162.111.101.209.9517 162.111.101.209.41918 162.111.101.209.9517 162.111.101.209.41937 162.111.101.209.41951... (7 Replies)
Discussion started by: Girish19
7 Replies
RECINS(1)							   User Commands							 RECINS(1)

NAME
recins - insert records in a recfile SYNOPSIS
recins [OPTION]... [t TYPE] [-n NUM | -e EXPR | -q STR | -m NUM] [(-f STR -v STR]|[-R RECDATA)]... [FILE] DESCRIPTION
Insert new records in a rec database. -f, --field=STR field name; should be followed by a -v. -v, --value=STR field value; should be preceded by an -f. -r, --record=STR record that will be inserted in the file. --force insert the record even if it is violating record restrictions. --no-external don't use external descriptors. --no-auto don't insert auto generated fields. --verbose give a detailed report if the integrity check fails. -s, --password=STR encrypt confidential fields with the given password. --help print a help message and exit. --version show version and exit. Record selection options: -i, --case-insensitive make strings case-insensitive in selection expressions. -t, --type=TYPE operate on records of the specified type only. -e, --expression=EXPR selection expression. -q, --quick=STR select records with fields containing a string. -n, --number=NUM,... select specific records by position, with ranges. -R, --random=NUM select a given number of random records. If no FILE is specified then the command acts like a filter, getting the data from standard input and writing the result to standard out- put. AUTHOR
Written by Jose E. Marchesi. REPORTING BUGS
Report bugs to: bug-recutils@gnu.org GNU recutils home page: <http://www.gnu.org/software/recutils/> General help using GNU software: <http://www.gnu.org/gethelp/> COPYRIGHT
Copyright (C) 2010, 2011, 2012 Jose E. Marchesi. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
The full documentation for recins is maintained as a Texinfo manual. If the info and recins programs are properly installed at your site, the command info recins should give you access to the complete manual. recins 1.4.93 January 2012 RECINS(1)
All times are GMT -4. The time now is 12:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy