i've a file as below


i want my grep to return the following results


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



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

which are returning

'ABC'|filler|'Y'|'john1'|'te/xt'    //i do not want this

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

1 Answer 1


Using grep

$ grep -E "^'ABC'\|[^|]*\|'(Y|N)'\|'[[:alpha:]]+/" input_file
  • hi, i've edited for a more accurate representation. for the 4th column, it is not literally 'name', just a representation. basically it can be any name, but i want to retrieve names with a / in it Oct 2, 2022 at 9:16
  • @UVERtainment Please check edit
    – sseLtaH
    Oct 2, 2022 at 9:18
  • Thank you. 1 more question if i may. would u happen to know how to remove only the / in the name, assuming there are / in the 5th column for the same single line? Oct 2, 2022 at 9:46
  • @UVERtainment That sounds like a new question in which case a new question should be asked with relevant samples and expected output. It also sounds like a question either sed or awk would handle easily.
    – sseLtaH
    Oct 2, 2022 at 9:48
  • 1
    @EdMorton I have addressed the issue. Thanks
    – sseLtaH
    Oct 3, 2022 at 9:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .