|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Read all files in a directory for a unix command
Hello, Below, I have a unix command, which can be executable for single file. Code:
cat input.txt | sort -k3,3 > output.txt I have 100 input files in a directory. It is hectic and time taking to run the above command for all the 100 files for 100 times. Now, I want to execute the above unix command to all the files in a directory. And the output should be written in an output directory with same input file name. Please help me in this. Thanks in advance.
Last edited by vbe; 06-27-2012 at 12:07 PM.. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Why use
cat ? Doesnt sort -k3,3 input.txt > output.txt work? For your directory you will need to use a loop and since your output is in another directory you can keep the same name as the one used as variable in the loop... Code:
for FILE in ... do sort -k3,3 $FILE >~newdirectory/$FILE . . done |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Similarly as it turned out: Code:
ls -1d * | while read filename
do
if [ -f "${filename}" ]
then
sort -k3,3 "${filename}" > "/your_path/your_directory/${filename}"
fi
done |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to read and append certain files form directory | lio123 | Shell Programming and Scripting | 2 | 02-09-2011 01:33 PM |
| Using Awk within awk to read all files in directory | flevongo | UNIX for Dummies Questions & Answers | 6 | 09-19-2009 04:47 PM |
| read files from directory | Satyak | Shell Programming and Scripting | 2 | 10-17-2008 05:20 AM |
| Read Files from a Directory | kiran_418 | UNIX for Dummies Questions & Answers | 2 | 04-18-2008 01:23 PM |
| unix command/s to find files older than 2 hours in a directory | Presanna | Shell Programming and Scripting | 6 | 11-20-2007 08:22 AM |
|
|