how to extract files one by one from a directory and let some processing happen


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to extract files one by one from a directory and let some processing happen
# 1  
Old 05-16-2008
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  
Old 05-16-2008
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  
Old 05-19-2008
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  
Old 05-19-2008
try this one

Code:
find /path/to/find -name "INTR*" | xargs nawk '{ some statments }'

# 5  
Old 05-19-2008
saniya: are you really sure? Works here.
# 6  
Old 05-19-2008
Hammer & Screwdriver 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

2. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

3. Shell Programming and Scripting

Extract files from tar ball without directory structure

Hi, I have tar filw which has multiple directories which contain files. When i extract using tar -xf the directory structure also get extracted. I require only files and not directory structures as there will be overhead of moving the files again. So i searched here and got a solution but... (4 Replies)
Discussion started by: chetan.c
4 Replies

4. UNIX for Dummies Questions & Answers

Loop through directory and extract sub directory names

I am trying to loop through folders and extract the name of the lowest level subfolder I was running the script below, it returns /bb/bin/prd/newyork /bb/bin/prd/london /bb/bin/prd/tokyo I really want newyork london tokyo I couldn't find a standard variable for the lowest level... (1 Reply)
Discussion started by: personalt
1 Replies

5. Shell Programming and Scripting

get all files from a directory and pass the files for processing

Hi All, I have a directory in which there will be several files. i want to get all the files and pass it to a piece of code for processing on the files. This is the piece of code which does the processing. tr "\n" "|" < (log file name) | tr "$" "\n" > output echo ' ' >>output while... (1 Reply)
Discussion started by: suresh_kb211
1 Replies

6. HP-UX

Processing very big directory

Hello, I have a very big directory with lots of small files. Just doing a single "ls" takes eternity, so I even can't know how many files the directory has. I need to get the newest files in the last 15 minutes, but I can't get an eficient way of doing it. I've tried find, perl, shell script,... (4 Replies)
Discussion started by: psimoes79
4 Replies

7. AIX

How does ITIL processing happen in AIX?

How does ITIL process is implemened in AIX? (6 Replies)
Discussion started by: AIXlearner
6 Replies

8. Shell Programming and Scripting

Processing files within a directory one by one

Hi How to create a shell script which takes in to account all the files present within a directory DIR one by one e.g. suppose i have a directory named DIR where there are files with the extension .ABC i want to create shell script which processes all these files one by one. ... (1 Reply)
Discussion started by: skyineyes
1 Replies

9. UNIX for Dummies Questions & Answers

extract tar files without creating directory

I received a tar file of a directory with 50,000 files in it. Is it possible to extract the files in the tar file without first creating the directory? ie. Doing tar -xvf filename.tar extracts as follows: x directory/file1.txt x directory/file2.txt . . . I would like to avoid... (4 Replies)
Discussion started by: here2learn
4 Replies

10. UNIX for Dummies Questions & Answers

What would happen if. . .

Hi, Could someone please tell me what would happen if the following were entered into the command line: rm -i /books/*.* rm /books/* Many thanks! (3 Replies)
Discussion started by: crispy
3 Replies
Login or Register to Ask a Question