Code: Select all
for file in *
do
cat "$file" > /tmp/xxx/xxx.tex
Googling googling but can't find a solution.
Taavi
Code: Select all
for file in *
do
cat "$file" > /tmp/xxx/xxx.tex
Code: Select all
#!/bin/bash
YEAR=`date +%Y`
# delete old and make new temp directories
rm /tmp/ltx/pieces/*.*
mkdir -p /tmp/ltx/pieces
# make preamble for the *.tex file
echo "\documentclass[12pt,a4paper,finnish]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[left=40mm,top=30mm,right=40mm,bottom=20mm,nohead]{geometry}
\setlength{\parindent}{0mm}
\begin{document}" >> /tmp/ltx/pieces/onefile.tex
#cat *.pox files
cd /mnt/home/writings/"$YEAR"/pieces
for file in *.pox
do
cat "$file" >> /tmp/ltx/pieces/onefile.tex
echo "
\vspace{1mm}
\rule{50mm}{0.1mm}
\vspace{1mm}
" >> /tmp/ltx/pieces/onefile.tex
done
# get end tag for the *.tex file
echo "
\end{document}" >> /tmp/ltx/pieces/onefile.tex
# run latex on the result and open the produced *.dvi file
cd /tmp/ltx/pieces
latex onefile.tex
xdvi -expertmode 4 -xoffset -0.1 -yoffset -0.1 -geometry 400x500 onefile.dvi
Code: Select all
#!/bin/bash
# file name is tavi for purpose of our
# discussion
# we build it by functions, the primary
# call is main - main calls other functions
# we can test functions independently by
# commenting out functions in main
main() {
simple_random
}
simple_random() {
# : is always true so the while loop is
# infinite
# we limit the random numbers to from
# 1 to 10000 with %10000+1
# as noted earlier RANDOM has a range
# from 0 to 32767
# this example shows how we can control
# the range although even more control
# is possible, but keeping things simple
# the important thing is your full
# understanding of this simple loop
# play around with it
# run it - change %value and learn
# terminate with Ctrl+C
while :
do
let NUM=${RANDOM}%10000+1
echo $NUM
done
}
main
Code: Select all
#!/bin/bash
main() {
# simple_random
numbered_symlinks
}
simple_random() {
echo data cut for brevity
}
numbered_symlinks() {
# cd to proper directory for pox files
# to be processed
[ ! -d /tmp/ltx ] && mkdir /tmp/ltx
[ ! -d /tmp/ltx/links ] && mkdir /tmp/ltx/links
[ ! -d /tmp/ltx/pieces ] && mkdir /tmp/ltx/pieces
CDIR=`pwd`
LINKDIR=/tmp/ltx/links
CNT=0
for i in *pox # or *.pox
do
CNT=`expr $CNT + 1`
echo ln -sf ${CDIR}/${i} ${LINKDIR}/${CNT}
# ln -sf ${CDIR}/${i} ${LINKDIR}/${CNT}
done
# Explained, use the echo first to see it it
# looks good. Then uncomment the actual command for
# a trial run
# Purpose in numbered symlinks: Simply to make
# (random + all + one time only) easier to implement
# Note: not tested at all
}
main
Bruce B wrote:Taavi,
You're clearly are a step ahead.
The primary objective for me is your learning and looks like you are doing it.
My next step will be a slightly more complex function, which understanding the building blocks should be easy to read, modify and control.
I expect to present it within 24 hours.
Ultimately it will be you polishing up the template for your use.
I don't know your time schedule but look back any time within the next 24 from time of this post.
Bruce
I notice I didn't comment on this so here is the explanationTaavi wrote: (And I have learned other way to delete and make temp directories.)
Code: Select all
#!/bin/bash
# a bash script is read from top to bottom
# it executes commands in the same manner
# the functions are read in and become
# programs within the script
# note the first command is the last line
# of the file, which is the call to main
# you can follow the entire program flow
# by reading the commands in main
# in outlining the program, I wanted to
# (first) verify the arguments and show
# help and exit as needed.
# (second) if arguments seem good then
# show the user a preview of the changes
# to be made before actually making them
# (third) get user explicit consent
# before making the changes
# (forth) if it is good to go, make the
# changes
# note you can do things like rename
# filenames.pet filenames.pet.tar.gz
main() {
checkarguments "$@" # exits on error
preview "$@"
permission # exits if permission not
# granted
# below is an unnecessary double check
# uses of x is a way of making sure
# either side of the comparision is
# never empty, quotes are also commonly
# used and shown in this script
[ x$REPLY = xy ] && mvextension "$@"
echo "" # for formatting only
}
checkarguments() {
# in this example we will nest functions.
# 'showhelp' will be a function within
# 'checkarguments'
showhelp() {
# $0 is the full path and name of program
# basename $0 is only the name of the
# program - stripping the path makes for
# nicer looking on screen display
# using the backslash \" allows quoting
# of the program name
# the initial name of the program is mvext
# but the script is structured such that
# it can be renamed
prgm=`basename $0`
echo ""
echo "Purpose of \"$prgm\" is to batch rename"
echo "file extensions"
echo
echo "Usage: \"$prgm\" <extension> <newextension>"
echo ""
echo "Note: \"$prgm\" will not make any changes or"
echo "overwrite files without your consent"
echo ""
exit
}
# if either are true help is shown
# the "" are used to make sure neither side
# of our string comparison test is ever
# empty
# the purpose of the argument check is to
# prevent the program from running in the
# absence of an argument and show help
# when it is obvious the user wants or
# needs help
# example usage of double string comparisons
# -o means "or" if either test is true
# showhelp runs
[ "$1" = "" -o "$2" = "" ] && showhelp
[ "$1" = "--help" -o "$1" = "-h" ] && showhelp
}
preview() {
# for loop will process all files matching our
# criteria of *$1
# basename is used for stripping filenames to
# our criteria - see man basename or
# basename --help for more information
# we bracket variables such as $i to ${i} to
# prevent any confusion by bash as to the
# variable name
for i in *"$1"
do
fn=`basename $i "$1"`
echo " mv ${fn}"$1" ${fn}"$2""
done
}
permission() {
# read used without specifying a variable, makes
# a variable called REPLY, which will be used
# the 'read' command is for getting user input
# during the operation of the program
read -n 1 -p " Proceed with actual renaming [y,n] "
[ x$REPLY != xy ] && echo "" && exit
}
mvextension() {
# in this function we do the actual renaming,
# the --interactive will halt in the event of
# a potential overwrite
for i in *"$1"
do
fn=`basename "$i" "$1"`
mv --interactive --verbose ${fn}"$1" ${fn}"$2"
done
}
main "$@"
Code: Select all
#!/bin/bash
main() {
checkarguments "$@"
preview "$@"
permission
[ x$REPLY = xy ] && mvextension "$@"
echo ""
}
checkarguments() {
showhelp() {
prgm=`basename $0`
echo ""
echo "Purpose of \"$prgm\" is to batch rename"
echo "file extensions"
echo
echo "Usage: \"$prgm\" <extension> <newextension>"
echo ""
echo "Note: \"$prgm\" will not make any changes or"
echo "overwrite files without your consent"
echo ""
exit
}
[ "$1" = "" -o "$2" = "" ] && showhelp
[ "$1" = "--help" -o "$1" = "-h" ] && showhelp
}
preview() {
for i in *"$1"
do
fn=`basename $i "$1"`
echo " mv ${fn}"$1" ${fn}"$2""
done
}
permission() {
read -n 1 -p " Proceed with actual renaming [y,n] "
[ x$REPLY != xy ] && echo "" && exit
}
mvextension() {
for i in *"$1"
do
fn=`basename "$i" "$1"`
mv --interactive --verbose ${fn}"$1" ${fn}"$2"
done
}
main "$@"