-1

How can I extract the substring after a / and compare the extracted value against another file ?

cat file 

/abc|98357|
abc/aabb|023947|
xyz/0102|293847|
pqr/pqrst|29384|
9864/truse|253123|

expected output :-

abc|98357|
aabb|023947|
0102|293847|
pqrst|29384|
truse|253123|

And then compare col 1 of file 1 with another file :-

aabb
pqrst
truse
1
  • 2
    You've asked a few questions recently that got awk answers so I expect you have some idea how to use awk now - please edit your question to show your attempt to solve the problem yourself.
    – Ed Morton
    Jun 21, 2022 at 18:47

1 Answer 1

2
awk -F'/' '{print $2}' file

produces your "expected output".


And then compare col 1 of file 1 with another file.

If you mean, "only print matching lines in file2 that match the first column of your 'expected output'", then the answer could be

comm -12 <(awk -F'[/|]' '{print $2}' file | sort) <(sort file2)

You must log in to answer this question.

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