|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Shell Script to append files
I have several content (text) files in a folder called "content" I have several google ads (text) files in a folder called "google_ads" Example: Code:
/content
/java
websphere.txt
android.txt
/microsoft
framework.txt
/c_sharp
linq.txtCode:
/google_ads
/java
websphere.txt
android.txt
/microsoft
framework.txt
/c_sharp
linq.txtI want to create a shell script that appends the files together and produces them in a "publish" folder Code:
/publish
/java
websphere.txt
android.txt
/microsoft
framework.txt
/c_sharp
linq.txtHow do I go about doing this? |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
How do I do this in a recursive fashion? |
|
#4
|
|||
|
|||
|
yes Code:
cat content/*.txt google_ads/*.txt foobar/*.txt >publish.file if you hit a maximum arguments error try this. Code:
find . -name \*.txt -exec cat {} \; > publish.file |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Try to run this on a script. You should be on the parent directory of content and google_ads Code:
#!/bin/bash
function main {
while read LINE; do
LINE=${LINE#*/}
echo "creating directory publish/$LINE..." || {
echo "failed."
return 1
}
mkdir -p "publish/$LINE"
done < <(exec find content/ -type d)
while read LINE; do
LINE=${LINE#*/}
echo "making file publish/$LINE..."
{
cat "content/$LINE"
[[ ! -f google_ads/$LINE ]] || cat "google_ads/$LINE"
} > "publish/$LINE"
[[ $? -eq 0 ]] || {
echo "failed."
return 1
}
done < <(exec find content/ -type f -iname '*.txt')
}
main |
| Sponsored Links | ||
|
![]() |
| Tags |
| append, copy, script, shell |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| To Create shell script files from a shell script | NehaB | Shell Programming and Scripting | 3 | 07-27-2010 11:29 PM |
| Shell script to identify the number of files and to append data | pradkumar | Shell Programming and Scripting | 4 | 05-26-2010 04:52 AM |
| How to append value at first line of CSV file using shell script? | anujrichhariya | Shell Programming and Scripting | 7 | 11-26-2009 10:28 AM |
| shell script to read a line in gps receiver log file and append that line to new file | gudivada213 | Shell Programming and Scripting | 3 | 06-24-2009 06:16 AM |
| Shell script to append a time for the existing error log file | gsprasanna | UNIX for Advanced & Expert Users | 12 | 07-12-2007 05:07 AM |
|
|