I am trying to capture the file name(which is not of fixed length) and put it in a variable. It is working in unix whereas when I am running the same script in Informatica it is not giving me the desired output. But when I comment the option(find the file name) then it is working fine. It can also because I am using awk. Is there any other way(other than using awk) to find the file name? File name will be in second line of the file with 2 other items filesize numeric(10) and record count numeric(8).
Here is my code:
#!/bin/ksh
eval $(awk 'NR==2 {
printf "header_fname=\"%s\"\n", substr($0,1,length-18) ## filename
}' $1)
echo "$header_fname"
Sample file:
id_xyz20070523085554004
abcdefgh.csv000000324100000036
header_fname=`awk 'NR==2 { print substr($0,1,length-18) }' $1`
echo $header_fname
or
#!/bin/ksh
{
read line
read line
} < $1
header_fname=${line%??????????????????}
echo $header_fname
Jean-Pierre.
mandab:
I am trying to capture the file name(which is not of fixed length) and put it in a variable. It is working in unix whereas when I am running the same script in Informatica it is not giving me the desired output. But when I comment the option(find the file name) then it is working fine. It can also because I am using awk. Is there any other way(other than using awk) to find the file name? File name will be in second line of the file with 2 other items filesize numeric(10) and record count numeric(8).
Here is my code:
#!/bin/ksh
eval $(awk 'NR==2 {
printf "header_fname=\"%s\"\n", substr($0,1,length-18) ## filename
}' $1)
echo "$header_fname"
Sample file:
id_xyz20070523085554004
abcdefgh.csv000000324100000036
In any BOURNE-type shell (bash, ksh, sh, etc.):
{
read line
IFS=0123456789 read header_fname junk
} < "$FILE"
echo "$header_fname"
cfajohnson:
In any BOURNE-type shell (bash, ksh, sh, etc.):
{
read line
IFS=0123456789 read header_fname junk
} < "$FILE"
echo "$header_fname"
Doesn't work if the file name contains any numeric character.
Jean-Pierre.
Mandab
May 29, 2007, 10:22am
5
Thank you Aigles, it is working perfectly.