Skip to main content
deleted 43 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 239

Hi I want to grep variable pattern which is in first column.

$ cat test.txt    
abc.xyz   
abc.def
pqr.tap
pqr.abc
abc.mnp
mnp.abc
abc.pqr
abc.mob

If variable pattern is abc then output should be

abc.xyz
abc.def
abc.mnp
abc.pqr
abc.mob

If variable pattern is mnp then output should be

mnp.abc

If pattern is not variable then I can do by command (For pattern mnp)

awk -F"." '{ if($1 == "mnp") print $0;}' test.txt

Please guide me for the variable pattern.

Hi I want to grep variable pattern which is in first column.

$ cat test.txt    
abc.xyz   
abc.def
pqr.tap
pqr.abc
abc.mnp
mnp.abc
abc.pqr
abc.mob

If variable pattern is abc then output should be

abc.xyz
abc.def
abc.mnp
abc.pqr
abc.mob

If variable pattern is mnp then output should be

mnp.abc

If pattern is not variable then I can do by command (For pattern mnp)

awk -F"." '{ if($1 == "mnp") print $0;}' test.txt

Please guide me for the variable pattern.

I want to grep variable pattern which is in first column.

$ cat test.txt    
abc.xyz   
abc.def
pqr.tap
pqr.abc
abc.mnp
mnp.abc
abc.pqr
abc.mob

If variable pattern is abc then output should be

abc.xyz
abc.def
abc.mnp
abc.pqr
abc.mob

If variable pattern is mnp then output should be

mnp.abc

If pattern is not variable then I can do by command (For pattern mnp)

awk -F"." '{ if($1 == "mnp") print $0;}' test.txt
Post Closed as "Duplicate" by steeldriver, Jeff Schaller, dhag, Satō Katsura, Kusalananda

Hi I want to grep variable pattern which is in first column.

cat test.txt

abc.xyz

abc.def

pqr.tap

pqr.abc

abc.mnp

mnp.abc

abc.pqr

abc.mob

$ cat test.txt    
abc.xyz   
abc.def
pqr.tap
pqr.abc
abc.mnp
mnp.abc
abc.pqr
abc.mob

If variable pattern is abcabc then output should be

abc.xyz

abc.def

abc.mnp

abc.pqr

abc.mob

abc.xyz
abc.def
abc.mnp
abc.pqr
abc.mob

If variable pattern is mnpmnp then output should be

mnp.abc

mnp.abc

If pattern is not variable then I can do by command (For pattern mnp)

awk -F"." '{ if($1 == "mnp") print $0;}' test.txt

awk -F"." '{ if($1 == "mnp") print $0;}' test.txt

Please guide me for the variable pattern. Thanks.

Hi I want to grep variable pattern which is in first column.

cat test.txt

abc.xyz

abc.def

pqr.tap

pqr.abc

abc.mnp

mnp.abc

abc.pqr

abc.mob

If variable pattern is abc then output should be

abc.xyz

abc.def

abc.mnp

abc.pqr

abc.mob

If variable pattern is mnp then output should be

mnp.abc

If pattern is not variable then I can do by command (For pattern mnp)

awk -F"." '{ if($1 == "mnp") print $0;}' test.txt

Please guide me for the variable pattern. Thanks.

Hi I want to grep variable pattern which is in first column.

$ cat test.txt    
abc.xyz   
abc.def
pqr.tap
pqr.abc
abc.mnp
mnp.abc
abc.pqr
abc.mob

If variable pattern is abc then output should be

abc.xyz
abc.def
abc.mnp
abc.pqr
abc.mob

If variable pattern is mnp then output should be

mnp.abc

If pattern is not variable then I can do by command (For pattern mnp)

awk -F"." '{ if($1 == "mnp") print $0;}' test.txt

Please guide me for the variable pattern.

Source Link
Vishal
  • 21
  • 1
  • 4

How to grep variable pattern which is in first column

Hi I want to grep variable pattern which is in first column.

cat test.txt

abc.xyz

abc.def

pqr.tap

pqr.abc

abc.mnp

mnp.abc

abc.pqr

abc.mob

If variable pattern is abc then output should be

abc.xyz

abc.def

abc.mnp

abc.pqr

abc.mob

If variable pattern is mnp then output should be

mnp.abc

If pattern is not variable then I can do by command (For pattern mnp)

awk -F"." '{ if($1 == "mnp") print $0;}' test.txt

Please guide me for the variable pattern. Thanks.