How to find complete file names in UNIX if i know only extention of file

Suppose I have a file which contains other file names with some extention [.dat,.sum etc].

text file containt

gdsds sd8ef g/f/temp_temp.sum yyeta t/unix.sum
ghfp hrwer h/y/test.text.dat
if[-r h/y/somefile.dat] then....
I want to get the complete file names, like for above file I should get output as

temp_temp.sum
unix.sum
test.text.dat
somefile.dat
I am using AIX unix in which grep -ow [a-zA-Z_] filename is not working as for AIX -o switch is not present.

Try:

cat filename | tr " " "\n" | grep "/" | xargs -n1 basename
# Convert all characters but a-zA-Z0-9_/. into spaces.
# Then convert all spaces into newlines.
sed 's/[^a-zA-Z0-9_/.]/ /g;s/ /\n/g' < file |
# Print the token after the last /.  Ignore lines with no / in them.
        awk -F/ 'NF>1 { print $NF }'

---------- Post updated at 01:16 PM ---------- Previous update was at 01:15 PM ----------

Useless Use of Cat

How to use tr without cat then? :slight_smile:

tr ... < inputfile | command2 

or, if you prefer it in front, that works too.

<inputfile tr ... | command2
1 Like