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
Assigning output to a variable jpmena Shell Programming and Scripting 3 03-27-2008 04:39 AM
Assigning output of command to a variable in shell sankar reddy Shell Programming and Scripting 6 02-28-2008 03:01 AM
assigning command output to a shell variable kprattip Shell Programming and Scripting 2 07-09-2007 05:01 AM
Assigning output of command to a variable oma04 Shell Programming and Scripting 5 06-27-2006 01:11 PM
Assigning nawk output to variables steveje0711 Shell Programming and Scripting 6 08-19-2005 06:03 PM

 
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
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 11-28-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Smile assigning nawk output to shell variable

Hello friends,

I doing the follwing script , but found problem to store it to a shell variable.


Code:
#! /bin/sh

for temp in `find ./dat/vector/ -name '*.file'` 
do
   echo $temp 
   nawk -v temp=$temp 'BEGIN{  split(temp, a,"\/"); print a[4]}'
done

output:
./dat/vector/drf_all_002.file
drf_all_002.file
......
......

It shows me all the file ending with .file under ./dat/vector directory.
But I want to store the value of ( in this case ) a[4] to a shell variable fname and also the base name of the file ie, drf in this case to a separate shell variable called basename..

If any other idea with sed or with any other command most welcome..

Objective is to find all the file with extension .file and then store only the file name to a shell variable
and the base name of the file to another shell variable.


Code:
#! /bin/sh

for temp in `find ./dat/vector/ -name '*.file'` 
do
   echo $temp 
   fname = `nawk -v temp=$temp 'BEGIN{  split(temp, a,"\/"); print a[4]}' `
done

I tried with the above code but getting error..

Thanks & Regards,
User_prady

Last edited by user_prady; 11-28-2007 at 09:21 PM..
 

Bookmarks

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 12:32 PM.


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