Skip to main content
edit 4th column for more accurate representation of names
Source Link

i've a file as below

'ABC'|filler|'Y'|'name'ABC'|filler|'Y'|'john/1'|'text' 'ABC'|filler|'Y'|'name1'|'te'ABC'|filler|'Y'|'john1'|'te/xt' 'ABC'|filler|'N'|'name'ABC'|filler|'N'|'mary/2'|'text' 'DEF'|filler|'N'|'name'DEF'|filler|'N'|'jane/3'|'text' 

i want my grep to return the following results

'ABC'|filler|'Y'|name'ABC'|filler|'Y'|john/1|'text' 'ABC'|filler|'N'|name'ABC'|filler|'N'|mary/2|'text' 

whereby the conditions are

  1. containing the word ABC
  2. matching the pattern of either 'Y' or 'N' and after the pipe should contain a forward slash

i'm currently stuck at

wordY="'Y'|"

wordN="'N'|"

grep ABC test.txt | grep "$wordY|$wordN"

which are returning

'ABC'|filler|'Y'|'name'ABC'|filler|'Y'|'john/1'|'text' 'ABC'|filler|'Y'|'name1'|'te'ABC'|filler|'Y'|'john1'|'te/xt'  //i do not want this 'ABC'|filler|'N'|'name'ABC'|filler|'N'|'mary/2'|'text' 

how do i add on to the command to return results values with forward slash in the 4th column as well?

i've a file as below

'ABC'|filler|'Y'|'name/1'|'text' 'ABC'|filler|'Y'|'name1'|'te/xt' 'ABC'|filler|'N'|'name/2'|'text' 'DEF'|filler|'N'|'name/3'|'text' 

i want my grep to return the following results

'ABC'|filler|'Y'|name/1|'text' 'ABC'|filler|'N'|name/2|'text' 

whereby the conditions are

  1. containing the word ABC
  2. matching the pattern of either 'Y' or 'N' and after the pipe should contain a forward slash

i'm currently stuck at

wordY="'Y'|"

wordN="'N'|"

grep ABC test.txt | grep "$wordY|$wordN"

which are returning

'ABC'|filler|'Y'|'name/1'|'text' 'ABC'|filler|'Y'|'name1'|'te/xt' //i do not want this 'ABC'|filler|'N'|'name/2'|'text' 

how do i add on to the command to return results values with forward slash in the 4th column as well?

i've a file as below

'ABC'|filler|'Y'|'john/1'|'text' 'ABC'|filler|'Y'|'john1'|'te/xt' 'ABC'|filler|'N'|'mary/2'|'text' 'DEF'|filler|'N'|'jane/3'|'text' 

i want my grep to return the following results

'ABC'|filler|'Y'|john/1|'text' 'ABC'|filler|'N'|mary/2|'text' 

whereby the conditions are

  1. containing the word ABC
  2. matching the pattern of either 'Y' or 'N' and after the pipe should contain a forward slash

i'm currently stuck at

wordY="'Y'|"

wordN="'N'|"

grep ABC test.txt | grep "$wordY|$wordN"

which are returning

'ABC'|filler|'Y'|'john/1'|'text' 'ABC'|filler|'Y'|'john1'|'te/xt'  //i do not want this 'ABC'|filler|'N'|'mary/2'|'text' 

how do i add on to the command to return results values with forward slash in the 4th column as well?

Source Link

How to grep a single line with a pattern containing single quotes, pipe and a pattern with a / after?

i've a file as below

'ABC'|filler|'Y'|'name/1'|'text' 'ABC'|filler|'Y'|'name1'|'te/xt' 'ABC'|filler|'N'|'name/2'|'text' 'DEF'|filler|'N'|'name/3'|'text' 

i want my grep to return the following results

'ABC'|filler|'Y'|name/1|'text' 'ABC'|filler|'N'|name/2|'text' 

whereby the conditions are

  1. containing the word ABC
  2. matching the pattern of either 'Y' or 'N' and after the pipe should contain a forward slash

i'm currently stuck at

wordY="'Y'|"

wordN="'N'|"

grep ABC test.txt | grep "$wordY|$wordN"

which are returning

'ABC'|filler|'Y'|'name/1'|'text' 'ABC'|filler|'Y'|'name1'|'te/xt' //i do not want this 'ABC'|filler|'N'|'name/2'|'text' 

how do i add on to the command to return results values with forward slash in the 4th column as well?