Hi,

Inputfile.log
TDR 30 /data/data2/log1
TDRM 60 /data/data2/log2

# This command will match both lines
$ grep ^TDR Inputfile.log

# This command will match lines with TDR word appear anywhere in the text (but not TDRM)
$ egrep -w TDR Inputfile.log


How can I just match TDR that appears only at the beginning of the line?

Cheers :)
lois

One way

grep  '^TDR '  Inputfile.log

One way

grep  '^TDR '  Inputfile.log

I tried that, but somehow it didn't work, maybe the input file was using tab....?

anyway, I have found this to be working

$ grep ^TDR Inputfile.log | awk '{ if ($1=="TDR") { print $0 } }'

Thank you.

cheers,
lois

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.