Skip to main content
deleted 52 characters in body
Source Link
Michael Mrozek
  • 95.7k
  • 40
  • 245
  • 236

can you please suggest how toHow do I pass variable within grep commandvariables into a grep command?

below hoard coded This hard-coded value is working:

startingLine=`grep -oP '(2017-01-03 )\w+.+' cv-batch.log | head -1`
echo $startingLine

but below parameterized version is notBut when I try to use a variable, it stops working -:

currDate=$(date -d "$dataset_date" +%Y-%m-%d)
echo $currDate
startingLine=`grep -oP '($currDate )\w+.+' cv-batch.log | head -1`

Update #1 -

Edit: I tried below commandthe following but it did not worked -didn't work either:

sartingLine=`grepstartingLine=`grep -oP '("$currDate" )\w+.+' cv-batch.log | head -1`

can you please suggest how to pass variable within grep command ?

below hoard coded value is working

startingLine=`grep -oP '(2017-01-03 )\w+.+' cv-batch.log | head -1`
echo $startingLine

but below parameterized version is not working -

currDate=$(date -d "$dataset_date" +%Y-%m-%d)
echo $currDate
startingLine=`grep -oP '($currDate )\w+.+' cv-batch.log | head -1`

Update #1 -

I tried below command but it did not worked -

sartingLine=`grep -oP '("$currDate" )\w+.+' cv-batch.log | head -1`

How do I pass variables into a grep command? This hard-coded value is working:

startingLine=`grep -oP '(2017-01-03 )\w+.+' cv-batch.log | head -1`
echo $startingLine

But when I try to use a variable, it stops working:

currDate=$(date -d "$dataset_date" +%Y-%m-%d)
echo $currDate
startingLine=`grep -oP '($currDate )\w+.+' cv-batch.log | head -1`

Edit: I tried the following but it didn't work either:

startingLine=`grep -oP '("$currDate" )\w+.+' cv-batch.log | head -1`
added 165 characters in body
Source Link
Raj
  • 121
  • 1
  • 1
  • 6

can you please suggest how to pass variable within grep command ?

below hoard coded value is working

startingLine=`grep -oP '(2017-01-03 )\w+.+' cv-batch.log | head -1`
echo $startingLine

but below parameterized version is not working -

currDate=$(date -d "$dataset_date" +%Y-%m-%d)
echo $currDate
startingLine=`grep -oP '($currDate )\w+.+' cv-batch.log | head -1`

Update #1 -

I tried below command but it did not worked -

sartingLine=`grep -oP '("$currDate" )\w+.+' cv-batch.log | head -1`

can you please suggest how to pass variable within grep command ?

below hoard coded value is working

startingLine=`grep -oP '(2017-01-03 )\w+.+' cv-batch.log | head -1`
echo $startingLine

but below parameterized version is not working -

currDate=$(date -d "$dataset_date" +%Y-%m-%d)
echo $currDate
startingLine=`grep -oP '($currDate )\w+.+' cv-batch.log | head -1`

can you please suggest how to pass variable within grep command ?

below hoard coded value is working

startingLine=`grep -oP '(2017-01-03 )\w+.+' cv-batch.log | head -1`
echo $startingLine

but below parameterized version is not working -

currDate=$(date -d "$dataset_date" +%Y-%m-%d)
echo $currDate
startingLine=`grep -oP '($currDate )\w+.+' cv-batch.log | head -1`

Update #1 -

I tried below command but it did not worked -

sartingLine=`grep -oP '("$currDate" )\w+.+' cv-batch.log | head -1`
Source Link
Raj
  • 121
  • 1
  • 1
  • 6

Passing parameter with-in grep command

can you please suggest how to pass variable within grep command ?

below hoard coded value is working

startingLine=`grep -oP '(2017-01-03 )\w+.+' cv-batch.log | head -1`
echo $startingLine

but below parameterized version is not working -

currDate=$(date -d "$dataset_date" +%Y-%m-%d)
echo $currDate
startingLine=`grep -oP '($currDate )\w+.+' cv-batch.log | head -1`