Sponsored Content
Top Forums Shell Programming and Scripting Script to batch pdfjoin based on pdfgrep output Post 302606162 by nopposan on Friday 9th of March 2012 05:11:47 PM
Old 03-09-2012
printf is nifty

Thanks!

Here's my updated script. I haven't tested it yet as I don't have any practice material at the moment.

Code:
#!bin/bash
# This script is written for files that are named with the pattern
#pg_0001.pdf, with leading zeros.

a=1 #Sets the starting page. 'Could set with user input.
b=$(($a+1))#Sets the next page equal to one more than the starting page.

Filename="pg_"`printf "%04d" $a`".pdf" # This is the filename of the
#starting page. The printf command is used to format the number with
#up to three leading zeros.

until [ $b == 680 ]; do # This line sets the maximum pages to be
#considered for concatenation.
Filename2="pg_"`printf "%04d" $b`".pdf" # This is the filename of the
#next file to be considered for concatenation to the current file.
x=`pdfgrep -C 0 [0-9]\{7\} $Filename | head -n 1` # pdfgrep with
#option to, -C, capture 0 characters other than the 7 digits in the
#employee ID; this is piped to "head" in order to get just the first
#occurrence.
y=`pdfgrep -C 0 [0-9]\{7\} $Filename2 | head -n 1`

if [ "$x" == "$y" ]; then 
    pdfjoin --rotateoversize 'false' $Filename $Filename2 --outfile $Filename # If the employee ID's are equal, then the pdf files
#are concatenated into a new file, which is given the name of the
#first file that's added to.
    rm $Filename2 # If the file is concatenated to a previous
#file, it is removed.
else
cp $Filename Empl_ID_"$x".pdf # Replace page number name with name
#based on Empl_ID.
#rm $Filename # Uncomment to remove the original file.
Filename=$Filename2 # If no match is found and the file is not
#concatenated, then advance the current origination file, Filename, to
#the name of the non-concatenated/non-matching file.
fi

b=$(($b+1)) # Advance the page number of the next file, Filename2.

done

cp $Filename Empl_ID_"$x".pdf # Finally, when all else is done,
#replace page number name with name of last file with one based on
#Empl_ID.

#rm $Filename # Uncomment to remove the original last file.

exit


Last edited by Corona688; 03-09-2012 at 06:32 PM.. Reason: Code tags, please.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to email based on flat file output

Hi All, I am a newbee in unix but still have written a shell script which should trigger a mail based on certain conditions but the problem is that my file is not being read. Below is the code please advise. I do not know where is it failing. Note $ and the no followed with it is the no of... (1 Reply)
Discussion started by: apoorva
1 Replies

2. Shell Programming and Scripting

Automatically Rerun a script based on previous execution output

Hi Experts, I have a shell script called "updatevs" that is scheduled to run at 6.00 am everyday via cronjob. The cronjob will execute this script and output to a log file. The functionality of this script is to read the database and run a set of commands. This script is generally successful... (6 Replies)
Discussion started by: forumthreads
6 Replies

3. Shell Programming and Scripting

Converting line output to column based output

Hi Guys, I am trying to convert a file which has a row based output to a column based output. My original file looks like this: 1 2 3 4 5 6 1 2 3 1 2 3 (8 Replies)
Discussion started by: npatwardhan
8 Replies

4. Shell Programming and Scripting

help with email to be triggered based on fatal error detection from batch run log file neded

Hi, I require need help in two aspects actually: 1) Fatal error that gets generated as %F% from a log file say ABClog.dat to trigger a mail. At present I manually grep the log file as <grep %F% ABClog.dat| cut-d "%" -f1>. The idea is to use this same logic to grep the log file which is... (1 Reply)
Discussion started by: zico1986
1 Replies

5. Shell Programming and Scripting

Executing a batch of files within a shell script with option to refire the individual files in batch

Hello everyone. I am new to shell scripting and i am required to create a shell script, the purpose of which i will explain below. I am on a solaris server btw. Before delving into the requirements, i will give youse an overview of what is currently in place and its purpose. ... (2 Replies)
Discussion started by: goddevil
2 Replies

6. UNIX for Advanced & Expert Users

Limiting size of rsync batch output

Anyone know if there's a way to limit the size of rsync batch output blob? I need each batch to fix on a 64GB USB key. Using syntax like: rsync -av --only-write-batch=/Volumes/usb/batch --stats /Users/dfbadmin/sandbox/ /Users/dfbadmin/archives/ (7 Replies)
Discussion started by: dfbills
7 Replies

7. Shell Programming and Scripting

Extract batch based on condition

HI, I have a file as mentioned below. Here one batch is for one user id.Batch starts from |T row and ends at .T row. I want to create a new file by reading this file. The condition is for record 10(position 1-2), if position 3 to position 17 is 0 then delete the entire batch and write into the new... (9 Replies)
Discussion started by: abhi.mit32
9 Replies

8. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

9. UNIX for Beginners Questions & Answers

Finding The Complete SQL statement Using PDFGREP Or Grep

Linux Gods, I am simply attempting to parse SQL statements from a PDF doc in creating a base SQL script at a later time but for the life of me, am having a tough time extracting this data.This exact string worked perfectly a couple of months ago and now it doesnt. Below is an example of the data... (4 Replies)
Discussion started by: metallica1973
4 Replies
filename(3erl)						     Erlang Module Definition						    filename(3erl)

NAME
filename - Filename Manipulation Functions DESCRIPTION
The module filename provides a number of useful functions for analyzing and manipulating file names. These functions are designed so that the Erlang code can work on many different platforms with different formats for file names. With file name is meant all strings that can be used to denote a file. They can be short relative names like foo.erl , very long absolute name which include a drive designator and direc- tory names like D:usr/localinerl/lib oolsfoo.erl , or any variations in between. In Windows, all functions return file names with forward slashes only, even if the arguments contain back slashes. Use join/1 to normalize a file name by removing redundant directory separators. The module supports raw file names in the way that if a binary is present, or the file name cannot be interpreted according to the return value of file:native_name_encoding/0 , a raw file name will also be returned. For example filename:join/1 provided with a path component being a binary (and also not being possible to interpret under the current native file name encoding) will result in a raw file name being returned (the join operation will have been performed of course). For more information about raw file names, see the file module. DATA TYPES
name() = string() | atom() | DeepList | RawFilename DeepList = [char() | atom() | DeepList] RawFilename = binary() If VM is in unicode filename mode, string() and char() are allowed to be > 255. RawFilename is a filename not subject to Unicode translation, meaning that it can contain characters not conforming to the Unicode encoding expected from the filesystem (i.e. non-UTF-8 characters although the VM is started in Unicode filename mode). EXPORTS
absname(Filename) -> string() Types Filename = name() Converts a relative Filename and returns an absolute name. No attempt is made to create the shortest absolute name, because this can give incorrect results on file systems which allow links. Unix examples: 1> pwd(). "/usr/local" 2> filename:absname("foo"). "/usr/local/foo" 3> filename:absname("../x"). "/usr/local/../x" 4> filename:absname("/"). "/" Windows examples: 1> pwd(). "D:/usr/local" 2> filename:absname("foo"). "D:/usr/local/foo" 3> filename:absname("../x"). "D:/usr/local/../x" 4> filename:absname("/"). "D:/" absname(Filename, Dir) -> string() Types Filename = name() Dir = string() This function works like absname/1 , except that the directory to which the file name should be made relative is given explicitly in the Dir argument. absname_join(Dir, Filename) -> string() Types Dir = string() Filename = name() Joins an absolute directory with a relative filename. Similar to join/2 , but on platforms with tight restrictions on raw filename length and no support for symbolic links (read: VxWorks), leading parent directory components in Filename are matched against trail- ing directory components in Dir so they can be removed from the result - minimizing its length. basename(Filename) -> string() Types Filename = name() Returns the last component of Filename , or Filename itself if it does not contain any directory separators. 5> filename:basename("foo"). "foo" 6> filename:basename("/usr/foo"). "foo" 7> filename:basename("/"). [] basename(Filename, Ext) -> string() Types Filename = Ext = name() Returns the last component of Filename with the extension Ext stripped. This function should be used to remove a specific extension which might, or might not, be there. Use rootname(basename(Filename)) to remove an extension that exists, but you are not sure which one it is. 8> filename:basename("~/src/kalle.erl", ".erl"). "kalle" 9> filename:basename("~/src/kalle.beam", ".erl"). "kalle.beam" 10> filename:basename("~/src/kalle.old.erl", ".erl"). "kalle.old" 11> filename:rootname(filename:basename("~/src/kalle.erl")). "kalle" 12> filename:rootname(filename:basename("~/src/kalle.beam")). "kalle" dirname(Filename) -> string() Types Filename = name() Returns the directory part of Filename . 13> filename:dirname("/usr/src/kalle.erl"). "/usr/src" 14> filename:dirname("kalle.erl"). "." 5> filename:dirname("\usr\src/kalle.erl"). % Windows "/usr/src" extension(Filename) -> string() Types Filename = name() Returns the file extension of Filename , including the period. Returns an empty string if there is no extension. 15> filename:extension("foo.erl"). ".erl" 16> filename:extension("beam.src/kalle"). [] flatten(Filename) -> string() Types Filename = name() Converts a possibly deep list filename consisting of characters and atoms into the corresponding flat string filename. join(Components) -> string() Types Components = [string()] Joins a list of file name Components with directory separators. If one of the elements of Components includes an absolute path, for example "/xxx" , the preceding elements, if any, are removed from the result. The result is "normalized": * Redundant directory separators are removed. * In Windows, all directory separators are forward slashes and the drive letter is in lower case. 17> filename:join(["/usr", "local", "bin"]). "/usr/local/bin" 18> filename:join(["a/b///c/"]). "a/b/c" 6> filename:join(["B:a\b///c/"]). % Windows "b:a/b/c" join(Name1, Name2) -> string() Types Name1 = Name2 = string() Joins two file name components with directory separators. Equivalent to join([Name1, Name2]) . nativename(Path) -> string() Types Path = string() Converts Path to a form accepted by the command shell and native applications on the current platform. On Windows, forward slashes is converted to backward slashes. On all platforms, the name is normalized as done by join/1 . 19> filename:nativename("/usr/local/bin/"). % Unix "/usr/local/bin" 7> filename:nativename("/usr/local/bin/"). % Windows "\usr\local\bin" pathtype(Path) -> absolute | relative | volumerelative Returns the type of path, one of absolute , relative , or volumerelative . absolute : The path name refers to a specific file on a specific volume. Unix example: /usr/local/bin Windows example: D:/usr/local/bin relative : The path name is relative to the current working directory on the current volume. Example: foo/bar, ../src volumerelative : The path name is relative to the current working directory on a specified volume, or it is a specific file on the current work- ing volume. Windows example: D:bar.erl, /bar/foo.erl rootname(Filename) -> string() rootname(Filename, Ext) -> string() Types Filename = Ext = name() Remove a filename extension. rootname/2 works as rootname/1 , except that the extension is removed only if it is Ext . 20> filename:rootname("/beam.src/kalle"). /beam.src/kalle" 21> filename:rootname("/beam.src/foo.erl"). "/beam.src/foo" 22> filename:rootname("/beam.src/foo.erl", ".erl"). "/beam.src/foo" 23> filename:rootname("/beam.src/foo.beam", ".erl"). "/beam.src/foo.beam" split(Filename) -> Components Types Filename = name() Components = [string()] Returns a list whose elements are the path components of Filename . 24> filename:split("/usr/local/bin"). ["/","usr","local","bin"] 25> filename:split("foo/bar"). ["foo","bar"] 26> filename:split("a:\msdev\include"). ["a:/","msdev","include"] find_src(Beam) -> {SourceFile, Options} | {error,{ErrorReason,Module}} find_src(Beam, Rules) -> {SourceFile, Options} | {error,{ErrorReason,Module}} Types Beam = Module | Filename Module = atom() Filename = string() | atom() SourceFile = string() Options = [Opt] Opt = {i, string()} | {outdir, string()} | {d, atom()} ErrorReason = non_existing | preloaded | interpreted Finds the source filename and compiler options for a module. The result can be fed to compile:file/2 in order to compile the file again. The Beam argument, which can be a string or an atom, specifies either the module name or the path to the source code, with or with- out the ".erl" extension. In either case, the module must be known by the code server, i.e. code:which(Module) must succeed. Rules describes how the source directory can be found, when the object code directory is known. It is a list of tuples {BinSuffix, SourceSuffix} and is interpreted as follows: If the end of the directory name where the object is located matches BinSuffix , then the source code directory has the same name, but with BinSuffix replaced by SourceSuffix . Rules defaults to: [{"", ""}, {"ebin", "src"}, {"ebin", "esrc"}] If the source file is found in the resulting directory, then the function returns that location together with Options . Otherwise, the next rule is tried, and so on. The function returns {SourceFile, Options} if it succeeds. SourceFile is the absolute path to the source file without the ".erl" extension. Options include the options which are necessary to recompile the file with compile:file/2 , but excludes options such as report or verbose which do not change the way code is generated. The paths in the {outdir, Path} and {i, Path} options are guaran- teed to be absolute. Ericsson AB stdlib 1.17.3 filename(3erl)
All times are GMT -4. The time now is 10:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy