<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Finding file extension in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972338#M95779</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;We get a file with different filenames like abc.123.ddmmyy.dat.gz or ddmmyy.hhmiss.dat or something.tar... etc.&lt;BR /&gt;&lt;BR /&gt;I need to copy these file based on their extension. Can you help me get the extension of the filenames? I tried using cut , awk. but they didn't help me much. Please advise.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 29 Mar 2007 16:19:15 GMT</pubDate>
    <dc:creator>hsrirama</dc:creator>
    <dc:date>2007-03-29T16:19:15Z</dc:date>
    <item>
      <title>Finding file extension</title>
      <link>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972338#M95779</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;We get a file with different filenames like abc.123.ddmmyy.dat.gz or ddmmyy.hhmiss.dat or something.tar... etc.&lt;BR /&gt;&lt;BR /&gt;I need to copy these file based on their extension. Can you help me get the extension of the filenames? I tried using cut , awk. but they didn't help me much. Please advise.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Mar 2007 16:19:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972338#M95779</guid>
      <dc:creator>hsrirama</dc:creator>
      <dc:date>2007-03-29T16:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Finding file extension</title>
      <link>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972339#M95780</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;One way:&lt;BR /&gt;&lt;BR /&gt;# echo abc.123.ddmmyy.dat.gz | perl -nle 'print $2 if /(.+)\.(.+)/'&lt;BR /&gt;&lt;BR /&gt;...returns 'gz'&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 29 Mar 2007 16:31:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972339#M95780</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-03-29T16:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Finding file extension</title>
      <link>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972340#M95781</link>
      <description>Here's a start -&lt;BR /&gt; ll /your_directory/ | awk '{print $9}' | grep -e gz -e dat -e zip -e tar &amp;gt; Some_file&lt;BR /&gt;&lt;BR /&gt;From there you will have the file names that match your criteria and it is elemetary to read this file for the file names and perform your copies.&lt;BR /&gt;&lt;BR /&gt;Best of luck.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;-dl&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Mar 2007 16:36:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972340#M95781</guid>
      <dc:creator>Dave La Mar</dc:creator>
      <dc:date>2007-03-29T16:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Finding file extension</title>
      <link>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972341#M95782</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Actually, we can use the Posix shell parameter substitution to do it the fastest:&lt;BR /&gt;&lt;BR /&gt;# F=abc.123.ddmmyy.data.gz&lt;BR /&gt;# echo ${F##*.}   &lt;BR /&gt;gz&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 29 Mar 2007 16:39:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972341#M95782</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-03-29T16:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Finding file extension</title>
      <link>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972342#M95783</link>
      <description>It would be helpful if you provided a few examples but something like this:&lt;BR /&gt;&lt;BR /&gt;cp *.gz /xxx/yyy/gzdir/&lt;BR /&gt;cp *.dat /xxx/yyy/tardir/&lt;BR /&gt;&lt;BR /&gt;Note: UNIX has no concept of a file extension; that belongs to another OS.&lt;BR /&gt;&lt;BR /&gt;If you wish to strip off a suffix then something like this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset BASE=""&lt;BR /&gt;typeset FNAME=""&lt;BR /&gt;typeset SUFFIX=".gz"&lt;BR /&gt;&lt;BR /&gt;ls | while read FNAME&lt;BR /&gt;  do&lt;BR /&gt;     BASE=$(basename "${FNAME}" "${SUFFIX}")&lt;BR /&gt;     if [[ "${BASE}" != "${FNAME}" ]]&lt;BR /&gt;       then&lt;BR /&gt;         echo "Basename: ${BASE}"&lt;BR /&gt;         # do your copy here&lt;BR /&gt;       fi&lt;BR /&gt;  done&lt;BR /&gt;&lt;BR /&gt;------------------------------------&lt;BR /&gt;You only see the base part of the filename with the suffix stripped off. Files not matching the suffix are ignored. Man basename for details.&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Mar 2007 16:46:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972342#M95783</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-03-29T16:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding file extension</title>
      <link>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972343#M95784</link>
      <description>Dave wrote...&lt;BR /&gt;&lt;BR /&gt;ll /your_directory/ | awk '{print $9}' | grep -e gz -e dat -e zip -e tar &amp;gt; Some_file&lt;BR /&gt;&lt;BR /&gt;Please tell me that you were just teasing and promiss you will never ever run software like that in production!&lt;BR /&gt;&lt;BR /&gt;what about files like:&lt;BR /&gt;stars.do_not_process&lt;BR /&gt;zippo_lighters_flyer&lt;BR /&gt;&lt;BR /&gt;You need to anchor those matches to the end of the string!&lt;BR /&gt;&lt;BR /&gt;Also, why pipe to grep when awk is perfectly happy to do regexpr's?&lt;BR /&gt;&lt;BR /&gt;Along the lines of...:&lt;BR /&gt;&lt;BR /&gt;ll | awk '/\.gz$|\.zip$|\.tar$/ {print $9}'&lt;BR /&gt;&lt;BR /&gt;Grins,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Mar 2007 18:11:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972343#M95784</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-03-29T18:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Finding file extension</title>
      <link>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972344#M95785</link>
      <description>&lt;!--!*#--&gt;hsrirama,&lt;BR /&gt;&lt;BR /&gt;Combining the above you probably want to build upon something like:&lt;BR /&gt;You probably want to deal with case when there is no suffix ($BASE==$FNAME)&lt;BR /&gt;&lt;BR /&gt;fwiw, I _love_ file extentions, as a hint such as used in OpenVMS. &lt;BR /&gt;In Windows they are followed overzealously imho. &lt;BR /&gt;If I want to call a text file .com no 'security' scan should barf and if I have an executable  file called .txt then a security scan should still find it.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset FNAME=""&lt;BR /&gt;typeset BASE=""&lt;BR /&gt;&lt;BR /&gt;ls | while read FNAME&lt;BR /&gt;do&lt;BR /&gt;BASE=${FNAME##*.}&lt;BR /&gt;case $BASE in&lt;BR /&gt; gz)  print Processing gunzip file $FNAME;;&lt;BR /&gt; tar) print Processing backup file $FNAME;;&lt;BR /&gt; *)   print Not processing $BASE file;;&lt;BR /&gt;esac&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Mar 2007 19:01:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972344#M95785</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-03-29T19:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Finding file extension</title>
      <link>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972345#M95786</link>
      <description>&amp;gt;Hein: BASE=${FNAME##*.}&lt;BR /&gt;&lt;BR /&gt;A slight nitpick.  The variable name should be SUFFIX.  Otherwise if you look to reuse the code you may think it is the basename.</description>
      <pubDate>Thu, 29 Mar 2007 22:52:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972345#M95786</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-03-29T22:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: Finding file extension</title>
      <link>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972346#M95787</link>
      <description>Hein -&lt;BR /&gt;Good point, well noted, and hands thoroughly slapped.&lt;BR /&gt;I'll crawl back in my hole now......&lt;BR /&gt;&lt;BR /&gt;-dl</description>
      <pubDate>Fri, 20 Apr 2007 12:47:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/finding-file-extension/m-p/3972346#M95787</guid>
      <dc:creator>Dave La Mar</dc:creator>
      <dc:date>2007-04-20T12:47:37Z</dc:date>
    </item>
  </channel>
</rss>

