I have a file
n06-z30-sr65-rgdt0p25-varp0.25-8x6drw-test.cmod
and I want to get the extension.
At the moment I have
set filextension = `echo $f | awk 'BEGIN {FS="."} {print $2}'`
which of course does not work as there is a point in varp0.25
I have a file
n06-z30-sr65-rgdt0p25-varp0.25-8x6drw-test.cmod
and I want to get the extension.
At the moment I have
set filextension = `echo $f | awk 'BEGIN {FS="."} {print $2}'`
which of course does not work as there is a point in varp0.25
what shell? modern bash:
var=n06-z30-sr65-rgdt0p25-varp0.25-8x6drw-test.cmod
echo ${var##*.}
cmod
If your shell has variable substitution, and assuming the extension is supposed to be "cmod"
Then this ought to work:
my_file=n06-z30-sr65-rgdt0p25-varp0.25-8x6drw-test.cmod
my_ext=${my_file##*.}
echo $my_ext
cmod
I am using csh
I need both the filename and the extension. At the moment it is as below
set filename = `echo $f | awk 'BEGIN {FS="."} {print $1}'`
set filextension = `echo $f | awk 'BEGIN {FS="."} {print $2}'`
#!/bin/csh
set pathvar=/home/WSJ091305.txt
echo $pathvar:r
echo $pathvar:h
echo $pathvar:t
echo $pathvar:e
#
# The result of executing this script is:
#
/home/WSJ091305
/home
WSJ091305.txt
txt
You want the last field, which in awk is referenced by $NF.
Regards,
Alister
I have done the below to get the file extension.
set filextension = `echo $f | awk 'BEGIN {FS="."} {print $NF}'`
But what should I do to get the file name?
see the previously posted csh specific hints.....
I have a string
set color = "blue/green/gold/black/red/purple/gray"
I want to remove the "/" and repalce it with a space. How can I do it in awk?
[ilan@posts ~]# color="blue/green/gold/black/red/purple/gray"
[ilan@posts ~]# echo $color | awk '{gsub(/\//," ");print}'
blue green gold black red purple gray
OR you can simply use tr to do that..
[ilan@posts ~]# echo $color | tr "/" " "
blue green gold black red purple gray
[ilan@posts ~]#
PS: you should have used a new thread instead of combining in old thread. I think, combining threads aren't entertained in forums.
Please don't piggy-back threads - start a new thread for a new question....
echo "blue/green/gold/black/red/purple/gray" | nawk -F/ '$1=$1'
Hi
You could try something like this
set color="`echo "blue/green/gold/black/red/purple/gray"|awk -F "/" '{print $1,$2,$3,$4,$5,$6,$7}'`"
Oh, ok. Apologies.