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 and shell scripting languages 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 11:11 PM
capture ping to a file MizzGail SUN Solaris 3 09-20-2007 10:31 AM
Capture Value from file kris01752 UNIX for Advanced & Expert Users 1 08-28-2006 11:50 PM
Capture the command run in the log file ahmedwaseem2000 Shell Programming and Scripting 4 08-09-2006 02:06 PM
capture nohup log file mgirinath Shell Programming and Scripting 2 04-24-2006 05:51 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-25-2007
Mandab Mandab is offline
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
  #2 (permalink)  
Old 05-25-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433

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.
  #3 (permalink)  
Old 05-25-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,365
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"

  #4 (permalink)  
Old 05-26-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
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.
  #5 (permalink)  
Old 05-29-2007
Mandab Mandab is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 22
Thank you Aigles, it is working perfectly.
Closed Thread

Bookmarks

Tags
bash, bash eval, eval

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0