Visit Our UNIX and Linux User Community


Linux script help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Linux script help
# 1  
Old 09-03-2009
Linux script help

I am creating a script that will incorporate multiple variables organized in a spreadsheet for pdftk. I have a 1000 page pdf that I have to split into about 300 individual pdfs. The basic command line to extract pages is as follows:

Code:
$ pdftk file.pdf cat 1-7  output newfile.pdf

file.pdf = 1000 page original file.
1-7 = pages to be extracted
newfile.pdf = new output file (pages 1-7 of 1000)

If I have a spreadsheet with all the sequential page numbers to be extracted in one column and the corresponding filename in another column, how do I insert those into the command line and have the script work through the entire list? I would appreciate any suggestions on how this could be done easier.

(noob I know, I ask for your patience)

Thanks
Tank.

Last edited by tankcommander; 09-04-2009 at 01:02 AM.. Reason: err
# 2  
Old 09-03-2009
Quote:
Originally Posted by tankcommander
I am creating a script that will incorporate multiple variables organized in a spreadsheet for pdftk. I have a 1000 page pdf that I have to split into about 300 individual pdfs. The basic command line to extract pages is as follows:

$ pdftk file.pdf cat 1-7 output newfile.pdf

file.pdf = 1000 page original file.
1-7 = pages to be extracted
newfile.pdf = new output file (pages 1-7 of 1000)

If I have a spreadsheet with all the sequential page numbers to be extracted in one column and the corresponding filename in another column, how do I insert those into the command line and have the script work through the entire list? I would appreciate any suggestions on how this could be done easier.

(noob I know, I ask for your patience)

Thanks
Tank.
Can you post ( say ...) first 10 lines of your spreadsheet file ? Exactly the way it is.
# 3  
Old 09-04-2009
If you had a flat file that contained the pages and file names like:
Code:
1-7 newfile1
8-234 newfile2
238-499 newfile3
500-1000 newfile4

then you code use something like this:
Code:
perl -nle '/(.+) (.+)/;qx(pdftk file.pdf cat $1 output $2.pdf)' infile

# 4  
Old 09-04-2009
Or ...

Code:
$ cat sample
1-7 file_1.pdf
8-14 file_2.pdf
15-22 file_3.pdf
23-30 file_4.pdf

Code:
while read s1 s2
  do
    pdftk file.pdf cat "$s1" output "$s2"
  done < sample

# 5  
Old 09-04-2009
Spreadsheet or flat file would look like:

1-5 newfile1.pdf
6-7 newfile2.pdf
8-15 newfile3.pdf
16-20 newfile4.pdf

bigfile.pdf is the original 1000 page pdf. . .
Code:
# pdftk bigfile.pdf cat 1-5 output newfile1.pdf
# pdftk bigfile.pdf cat 6-7 output newfile2.pdf
# pdftk bigfile.pdf cat 8-15 output newfile3.pdf
# pdftk bigfile.pdf cat 16-20 output newfile4.pdf

# 6  
Old 09-04-2009
Quote:
Originally Posted by tankcommander
Spreadsheet or flat file would look like:

1-5 newfile1.pdf
6-7 newfile2.pdf
8-15 newfile3.pdf
16-20 newfile4.pdf

bigfile.pdf is the original 1000 page pdf. . .

Both solutions guessed the right format of the spreadsheet file, and they worked OK. The problem is already solved.

P.S.
BTW, thanks for posting the file, I just wanted to confirm I was working with the right sample.
# 7  
Old 09-11-2009
one more

Thanks, for all the suggestions. One more question. If I want to insert two variables to create a more complex output filename, what would be the easiest way?

For example, if my flat file/spreadsheet included a third variable, a year, it would look like this:

Code:
1-7 newfile1 1993
8-234 newfile2 2002
238-499 newfile3 2006
500-1000 newfile4 2009

I wanted to combine the second and third variables ("newfile1" and "1993") together, separated by a dash/hyphen as part of the output filename, the actual commands would look like this:
Code:
# pdftk bigfile.pdf cat 1-5 output newfile1-1993.pdf
# pdftk bigfile.pdf cat 6-7 output newfile2-2002.pdf
# pdftk bigfile.pdf cat 8-15 output newfile3-2006.pdf
# pdftk bigfile.pdf cat 16-20 output newfile4-2009.pdf

what would be the easiest method to have the two variables inserted, separated by a dash/hyphen, and then add the .pdf extension?

Thanks for your help, again. Much appreciated.

Previous Thread | Next Thread
Test Your Knowledge in Computers #583
Difficulty: Easy
Buffered input/output is used because I/O operations can slow the system down.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux script - help!!

I need to create a bash script to run through crontab, to do the below job: 1- find files that are over 12 months old in /var "files are like file_201201222.mtd file_201201333.mtd 2- Tar them in /backup like: file_201201.tar.bz2 "every month in one tar file" 3- remove them after that 4- Send... (8 Replies)
Discussion started by: Ahmad M. Kamel
8 Replies

2. Shell Programming and Scripting

Linux script

can anyone help in this i have a file like 2089,success 2089,failure 2087,failure 2089,success 2087,failure. i want output like. 2089,success=2,failure=1 2087,success=1,failure=2 thanks (8 Replies)
Discussion started by: pradeep rawat
8 Replies

3. UNIX for Dummies Questions & Answers

Linux script

Hello, could you please help me with the following request? I need a linux command script that does the following. 1. delete folders folder1 and folder2 located in install/users/web/folder1&2. and also delete folder3 install/jboss/server/folder3. All these folders has many folder and files... (1 Reply)
Discussion started by: bern11
1 Replies

4. Shell Programming and Scripting

Need help! Linux shell script

Hi all, I am trying to make a Nodemanager work in RHEL 5 I got this script from 'oraclemiddleware.wordpress.com', and made appropriate changes to suit my weblogic installation. I keep getting the error, "line 82: syntax error: unexpected end of file". I have checked every line to make sure all... (4 Replies)
Discussion started by: chakrv1
4 Replies

5. Shell Programming and Scripting

Need linux script!!

I have a text file like this: 25 raj 78 rohit 89 bhanu 58 mohit 29 mano 53 rohit 63 shiva 74 lapan 63 bhanu what i need is a linux script to reorganize this file by adding the relevant content(number) to the names and print only once.... please help me someone. ... (1 Reply)
Discussion started by: shan1990
1 Replies

6. Shell Programming and Scripting

Help, Linux Script

#!/bin/sh args=("$@") echo "#=================================" echo "#Script Name:" echo "#By:" echo "#Purpose:" echo "#:Command Line: picoc" echo "#=================================" pico $@ this is my script. i think it is ok w/o error. but when i run it i got error. i'm using a VMBox... (1 Reply)
Discussion started by: jrdncchr
1 Replies

7. Linux

linux script

I need to write a script to which need to track errors in log and need to check last 100 lines in the log at every 5 minits. if error fund need to mail my self error type 1. "STATE_ADMIN" if found need to print: <Jan 5, 2011 11:47:02 AM IST><ewaps2> <ADFAPPS2> < STATE_ADMIN 2."Java heap... (0 Replies)
Discussion started by: udara
0 Replies

8. Shell Programming and Scripting

Help with linux bash script

Hello everybody! This is my first time having to write a script so your help is most appreciated.Also i am a beginner when it comes to linux so please bare with me.Thanks in advance to all who will look into this for me. I have to write a bash script that will show the free space on the hard... (4 Replies)
Discussion started by: manike
4 Replies

9. Shell Programming and Scripting

help with linux shell script

HI im a novice with shell scripts but i need help with a random script I have this folder filled with 500 different file names... I need help creating a script that will take each filename and make a new folder named that filename and then move that file into the newly created folder. Then the... (1 Reply)
Discussion started by: emachala
1 Replies

10. Shell Programming and Scripting

Linux Script help

Hi Everyone , have a nice day given below is a simple linux script but its first part is not working ( variable k assignment ) , while second loop is working fine can anyone help me out with this #!/bin/sh echo "Enter Date" read date1 for i in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14... (6 Replies)
Discussion started by: Dastard
6 Replies

Featured Tech Videos