Operating System - HP-UX
1823015 Members
3655 Online
109645 Solutions
New Discussion юеВ

Re: Working with files in a directory

 
Mauro_8
Frequent Advisor

Working with files in a directory

Hi,

I have a directory with a lot of 'ascii' files. The names are not the same when I run the procedure that create these files. Each file has three columns and I have to do a script that get each file and if the name start with ABC put it??s contents into another file. So what I really want is similar to give a ls command and treat each file, testing if each file is in my scope. So, for example, if one of the files are ABC1234.txt, I would do "more $name_file >> example.txt" where $name_file the script should get from ls command from the files that is in my scope. The contents of every file started with ABC must be in example.txt.

Cheers,
Mauro
4 REPLIES 4
Patrick Wallek
Honored Contributor

Re: Working with files in a directory

#!/usr/bin/sh

for i in $(ls -1 ABC*)
do
cat $i >> example.txt
done


The above script will look for all files starting with ABC and do a cat on them with the contents of ALL of the files being put in example.txt.
Justo Exposito
Esteemed Contributor

Re: Working with files in a directory

Hi Mauro,

You can do something like that:

for i in ABC*
do
cat $i >> exmaple.txt
done

Regards,

Justo.
Help is a Beatiful word
Heiner E. Lennackers
Respected Contributor

Re: Working with files in a directory

Hi,

if i understand you correctly (and i doubt about it, because it is to easy), all you need to do is:

cat ABC*.txt >>example.txt


Heiner
if this makes any sense to you, you have a BIG problem
Mauro_8
Frequent Advisor

Re: Working with files in a directory

Ok...

It??s really easier than I had planned.

Cheers,
Mauro