The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to capture new lines in a file and copy it to new file fara_aris Shell Programming and Scripting 0 05-27-2008 07:11 PM
capture ping to a file MizzGail SUN Solaris 3 09-20-2007 06:31 AM
Capture Value from file kris01752 UNIX for Advanced & Expert Users 1 08-28-2006 07:50 PM
Capture the command run in the log file ahmedwaseem2000 Shell Programming and Scripting 4 08-09-2006 10:06 AM
capture nohup log file mgirinath Shell Programming and Scripting 2 04-24-2006 01:51 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-25-2007
Registered User
 

Join Date: Apr 2007
Posts: 22
capture the file name

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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-25-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,199
Code:
header_fname=`awk 'NR==2 { print substr($0,1,length-18) }' $1`
echo $header_fname
or
Code:
#!/bin/ksh
{
  read line
  read line
} < $1
header_fname=${line%??????????????????}
echo $header_fname
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 05-25-2007
cfajohnson's Avatar
Registered User
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 487
Quote:
Originally Posted by 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.):

Code:
{
 read line
 IFS=0123456789 read header_fname junk
} < "$FILE"
echo "$header_fname"
Reply With Quote
  #4 (permalink)  
Old 05-26-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,199
Quote:
Originally Posted by cfajohnson
In any BOURNE-type shell (bash, ksh, sh, etc.):

Code:
{
 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.
Reply With Quote
  #5 (permalink)  
Old 05-29-2007
Registered User
 

Join Date: Apr 2007
Posts: 22
Thank you Aigles, it is working perfectly.
Reply With Quote
Google UNIX.COM
Reply

Tags
bash, bash eval, eval

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0