How to grep file paths out of a text file

grepsedtext processing

I have a file that has a list of paths like so:

"1"       "/user/bin/share"
"2"       "/home/user/.local"
"3"       "/root/"

Is there a way to extract just the paths? I dont want the numbers or quotation marks. How can I sed or grep the paths out of the file? What regex would be required for such a task?

Best Answer

If all the paths start with /, you could just match / followed by a sequence of non-" characters:

$ grep -o '/[^"]*' file
/user/bin/share
/home/user/.local
/root/

Alternatively, for a more structured approach, use awk to strip quotes from and print just the second field:

awk '{gsub(/"/,"",$2); print $2}' file
Related Question