batch cat with a file name
Hi guys,
I need to run the cat command over several files, and have it keep adding onto a summary file, something like: psuedo-code Code:
cat ABC.txt DEF.txt > summary.sum but I also need to have the files' names inside the summary.sum file for each block of data that was cat'd in, something like this for the output summary.sum file format Code:
Tabitha |
Try this:
for file in ABC.txt DEF.txt GHI.txt; do echo $file cat $file echo done > summary.txt |
You need to use the echo command to print the file name I threw together a quick script that did what you asking
Code:
#!/bin/bash I tried it on 4 files named exfile_1, exfile_2 etc.. Which took the form: Code:
File1_Line1 Code:
./cat_files_with_names.sh exfile_{1..4}.txt Code:
exfile_1.txt HTH - let me know if this is the solution you where looking for. |
I used the command:
Code:
sh ./cat_files_with_names.sh exfile*.txt I have never seen the bash "$@" what is that doing? and what's the difference between > and >> thanks again, Tabitha |
If you use the shebang line at the top of a shell script thus
Code:
#!/bin/sh The input params to a shell script can be expressed as an array ($@) or as a single string ($*). > = overwrite/start a new file >> = append to target See these links for ref http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
Thanks Chris!
Tabby |
All times are GMT -5. The time now is 05:40 AM. |