The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
tar extract to different directory ammu UNIX for Advanced & Expert Users 1 07-25-2007 10:54 AM
Processing files within a directory one by one skyineyes Shell Programming and Scripting 1 07-16-2007 01:44 AM
extract tar files without creating directory here2learn UNIX for Dummies Questions & Answers 4 10-02-2006 07:42 PM
How to extract archive to a specified directory john_trinh UNIX for Dummies Questions & Answers 4 03-02-2004 06:07 PM
redirecting tar extract to another directory colesy UNIX for Dummies Questions & Answers 7 01-28-2003 04:40 AM

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-16-2008
saniya saniya is offline
Registered User
  
 

Join Date: May 2008
Posts: 4
how to extract files one by one from a directory and let some processing happen

how to extract files one by one from a directory and let some processing be done on the file

I have a directory by name INTRN which has files like

INTR.0003080248636814
INTR.0003080248636816
INTR.0003080248636818
.
.
.
.
and so on

and in a script i have a nawk block
nawk '{
.
.
.

}' <filename>

my problem is how to how to extract files one by one from a directory and place it at the end of the nawk block,like get the file
INTR.0003080248636814 from the directory INTRN and put it at the end of the nawk block for processing,aftr processing get the second file and do the same for all the files in the directory.
please help me.thanks in advance.
  #2 (permalink)  
Old 05-16-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
check if this helps you:
Code:
for file in INTR* ; do  nawk '/hi/ {print $0}' $file ; done
replace the nawk command with whatever you have
  #3 (permalink)  
Old 05-19-2008
saniya saniya is offline
Registered User
  
 

Join Date: May 2008
Posts: 4
that solution is nt working properly,every time it is refering to the same file
it is not refering to the next file,plz provide a solution.thnx in advance.
  #4 (permalink)  
Old 05-19-2008
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
try this one

Code:
find /path/to/find -name "INTR*" | xargs nawk '{ some statments }'
  #5 (permalink)  
Old 05-19-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
saniya: are you really sure? Works here.
  #6 (permalink)  
Old 05-19-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Here is a section of code to build off of...

The following example reads through files finding files that match the input criteria, and then creates new filenames.

Code:
tailprg="/usr/local/bin/tail" #force version of tail command

echo "Shortening the filenames"
for rf in *_DAT; do
   echo "Creating .dat for $rf"
   tf=dm`basename $rf _DAT | $tailprg -c6`.dat
   cp $rf $tf
done
You should be able to insert your code/commands inside the loop.
Closed Thread

Bookmarks

Tags
directory, for-while-loops, xargs

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 11:55 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