I've written the script below to merge only .txt files that exist in one directory into one huge .txt file and ignore other files with other extensions.
now the result is one huge .txt file with all the contents of other .txt files
how can i add a File Name as a comment before each file?
i think i should specify the path in the system because i want to merge each directory with all .txt files in it in a separate file.
meaning
Directory A: has many files, i want to merge all .txt files in this directory only
Directory B: same thing merge all .txt file exist in this directory only.
and so forth.
when i executed the script u posted I got this error:
ls: cannot access /path/to/my/directories/*.txt: No such file or directory
When i removed system='/path/to/my/directory/DirectoryA'
i got this error
ls: cannot access /*.txt: No such file or directory
From the errors it gave you, it sounds like it's having trouble finding either the files or directories. I would verify that your path is correct. You could add a test for the directory in the script that could tell you this:
As for wanting to repeat this on more directories, you could wrap a for loop around the above code like this:
This is where I would define a function and pass the directory you want to process to the function as an argument. I hope that helps you.
Thank you for your response.
I think i didnt explain what i need clearly,
I have 145 directories each one has many files,
for example one of the directories is
ClassA that has grade.txt subjects.txt courses.txt description.xml
i want to have one file called ClassA.txt that contanis all the contents of grade.txt , subject.txt , courses.txt
and each part in ClassA.txt should have comment '//' and the file name
i.e
ClassA.txt
would be like
//grade.txt
[content of grade .txt]
// subject.txt
[content of subject.txt]
and so forth
what i've managed to do so far is
i dont want to display the path of $txtfile as shown in the code above rather i would like to append the vale of $txtfile before each .txt file
unfortunately the code above isnt working, am getting permession denied error!
I am trying to compare/confirm the output of an script using the perl below, which does execute. However I can not seem to print $1 and $2 in each line of the input separated by a tab in each line of the output. The input file is quite large so I have only included a portion, but the format is the... (0 Replies)
I have two files for comparison which are extracts from set of xml files.
file1 has:
Comparing File: BRCSH1to320140224CC3.xml
:: TZZZ:BR
:: TAZZ:OUT
UIZZ:0 :: ERAZ:1.000000
UIZZ:0 :: CTZZ:B
UIZZ:0 :: CCAZ:MYR
Comparing File: BRMY20140224CC18REG013SPFNSY13.xml
:: TZZZ:BR
:: TAZZ:INB... (1 Reply)
What would be the best way to store the name of an extracted file from a tar to a text file?
I want to extract one file from a tar and store the name of the extracted file to a temp file.
tar -xvf tar_file.tar file_to_be_extracted (1 Reply)
Hi,
Please excuse for posting new thread on control characters,
I am facing some difficulties in removing the control character from a file extracted from top command,
i am able to see control characters using more command and in vi mode, through cat control characters are not visible ... (8 Replies)
Iam trying to execute a file that include many files but it seems my main copy.c can't read anyone of them
-----------------------------------------------------------------------------------------
Copy.c
#include <sys/stat.h>
#include <fcntl.h>
#include "tlpi_hdr.h"
#ifndef BUF_SIZE /*... (2 Replies)
If I have a script that is using
unrar e file.part1.rar
How does the script get the name of the extracted file if I don't know the extension of the file?
In my example the name would be file.***, but I wouldn't know the extension.
---------- Post updated at 05:13 PM ---------- Previous... (0 Replies)
Hi All,
I have a big file which looks like this:
0 4.5 6.7
0 3.4 6
1 5 6
1 6 4
2 9 4.44
Above is just a miniature version of the file. In fact, considering the first column of the file that is 0 0 1 1 2, the numbers in actual go until 10442.
This means my actual file looks like... (2 Replies)
Hi All,
In make file i want to include header files from my local directory and if it did not find in local directory i want to include from network directory. can any help me how i can do this?.
here is the code
INCLUDE=${include}/
this is point to network dir how i can add option that it... (1 Reply)
I am trying to run a script called install.sh as follows:
I get a jar file, and extract it using the command:
unzip filename.jar -D path/to/files
then I navigate to that directory where I extracted the files, and run the command:
sh install.sh
(where install.sh is one of the files... (12 Replies)
Hi,
I have been trying to shoot an email with the email body to be obtained from a file.
Can someone please help me with it..
I have been trying to use the MAILX commad for the same.
mailx -s "test email" -r sender@test.com < file.txt
but it sends the file as an attachment,while i... (3 Replies)