Awk: Search for string containing "/"
Hello!
I want to search 2 strings (i.e. 6/Dec/2012 and string2) in a file file1 using awk. But problem is, how to avoid "/" in search string. Code is somethnig like: Code:
day=6 # Input taken from user Code:
day=6 # Input taken from user --------- ADDING INFO --------- I have tried with following also, but... :( Code:
format=$day\\/$month\\/$year |
I can't help with awk, but for sed the following works
Code:
#!/usr/bin/bash This means: When Bash should expand the variables, they have to be between doublequotes " and not singlequotes ' Markus |
The problem arises from the use of single quotes (the shell does not expand variable).
You can still use single quotes, but you need to do it this way: Code:
awk '/'$DAY'\/'$MONTH'\/'$YEAR'/ { print }' infile Code:
awk "/$DAY\/$MONTH\/$YEAR/ { print }" infile Code:
sed -n "/$DAY\/$MONTH\/$YEAR/p" datefile |
Quote:
Markus |
Quote:
Code:
nawk -v date="$day/$smonth/$year" '$0 ~ date && $11 ~ "string2" {gsub(/string2=/,"",$11); print $11}' file1 |
Thanks everyone. It's resolved using both solutions, either by using single quotes inside single quotes or declaring the varialbe outside of search pattern.
|
All times are GMT -5. The time now is 03:39 PM. |