Hi All,
I'm new to Linux. I'm facing an issue. I need to iterate through all the files in a folder and concatenate File Name with the contents of file and store output in one file.
Eg.
File1 (Contents)
7 1 0 1
6 1 0 1
5 1 0 1
4 1 0 1
3 1 0 1
2 1 0 1
1 1 0 1
File2 (Contents)
664 1 0 1
664 1 0 1
664 1 0 1
664 1 0 1
664 1 0 1
664 1 0 1
664 1 0 1
664 1 0 1
664 1 0 1
File3(Expected Output after processing)
File1 7 1 0 1
File1 6 1 0 1
File1 5 1 0 1
File1 4 1 0 1
File1 3 1 0 1
File1 2 1 0 1
File1 1 1 0 1
File2 664 1 0 1
File2 664 1 0 1
File2 664 1 0 1
File2 664 1 0 1
File2 664 1 0 1
File2 664 1 0 1
File2 664 1 0 1
File2 664 1 0 1
File2 664 1 0 1
I did tried to work on this but facing some issue.
sed 's/^/\t/' File1.txt | sed 's/^/File1.txt/' >> File3.txt
sed 's/^/\t/' File2.txt | sed 's/^/File2.txt/' >> File3.txt
This sed script works for individual file. But I've about 500 files. One more issue I'm facing is with the file naming convention. Some example names are as below.
11File.txt
- File2.txt
(-) File3.txt
File_4.txt
File-5.txt
(+) File6.txt
+ File2.txt
-TMS_S.txt
I also tried to create a loop for iteration through all the files in a folder but it is giving me some error.
#!/bin/sh -f
for myfile in *.txt
do
echo $myfile
done
'yScript.sh: line 3: syntax error near unexpected token `do
'yScript.sh: line 3: `do
Please help me to solve this issue.
Thanks & Regards
Manoj
[Updated on: Tue, 08 October 2013 01:22]
Report message to a moderator