How to parse filename and one level up directory name?

Hello Experts,

I need little help with parsing.
I want to parse filename and one level up directory name.
sample $1 will consists of
/home/username/ABC1/rstfiles4.log
/home/username/ABC4/rstfiles2.log
/home/username/EDC7/rstfiles23.log
/home/username/EDC6/rstfiles55.log
/home/username/rstfiles15.log

So in this i want to parse like
ABC,rst*.log
EDC,rst*.log
,rst.log

Please help me to get this output.

Thanks in advance!!

$ cat test.in
/home/username/ABC1/rstfiles4.log
/home/username/ABC4/rstfiles2.log
/home/username/EDC7/rstfiles23.log
/home/username/EDC6/rstfiles55.log
/home/username/rstfiles15.log

$ sed 's:^/home/username/::' test.in |
sed 's:^\(...\).*/:\1,:' |
sed 's:\,\(...\)[^.]*:,\1*:' |
sed 's:^\([^,][^,][^,]\)[^,]*\.:,\1.:' | uniq
ABC,rst*.log
EDC,rst*.log
,rst.log

Thanks Chubler_XL..
my path is not fixed. my script takes path as input parameter...
and that path contains the common characters like
any path/ABC*/rst*.log
any path/EDC*/rst*.log
any path/rst*.log

Becuase after getting this,ABC* or EDC* i will need to perform action on that like ABC.* == ABC.* then direct it ot csv file

If you can give some idea..will be greatful

This should work for you then, path is in variable mypath (without trailing slash):

sed "s:^${mypath}/::" test.in |
sed 's:^\(...\).*/:\1,:' |
sed 's:\,\(...\)[^.]*:,\1*:' |
sed 's:^\([^,][^,][^,]\)[^,]*\.:,\1.:' | uniq

I am getting the below output:

exp,201*.
exp,201*
exp,201*.
exp,or .
exp,201
.
exp,201*
exp,201*.
exp,201*

that is first 3 character of path and then last 3 character of $1 appended by *.

assuming you put everything into a file, exactly as you describe.

for i in `cat filename`
do
   BASE=`basename $i`
   DIR=`dirname $i | xargs basename`
   echo $DIR "," $BASE
done

Isn't that what you asked for in your original post? What exactly do you want?

Coul you please provide the sample of exact output that you want from your input??:slight_smile:

i figured it out the solution ...
Thanks for your help.