Need to grep only the word between the 2nd and 3rd to last /
This is shown in the extract below, to note that the location on the filename is not always the same counting from the front. Any ideas would be helpful.
/home/user/Drive-backup/2010 Backup/2010 Account/Jan/usernameneedtogrep/user.dir/4.txt
I’d use
awk:/NFis the index of the last column,$NFthe last column itself and$(NF-2)the 3rd-to-last column.You might of course first need to filter out lines in your input that are not paths (e.g. using
grepand then piping toawk)