0

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?

1 Answer 1

0

Using grep

$ grep -E "^'ABC'\|[^|]*\|'(Y|N)'\|'[[:alpha:]]+/" input_file 'ABC'|filler|'Y'|'john/1'|'text' 'ABC'|filler|'N'|'mary/2'|'text' 
5
  • 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 Commented Oct 2, 2022 at 9:16
  • @UVERtainment Please check edit Commented 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? Commented 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. Commented Oct 2, 2022 at 9:48
  • 1
    @EdMorton I have addressed the issue. Thanks Commented Oct 3, 2022 at 9:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.