Script to append text from one file into another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to append text from one file into another
# 15  
Old 07-05-2010
OK.

You are right - I think I can figure out the paths and file names.

However, is there a way to make this a stand alone script - that is, I want to be able to run it when necessary as some jobs require this and some do not.

So, here is my question:

Does the following make sense:
Code:
#!/bin/bash
#PBS -l nodes=1:ppn=8,walltime=48:00:00,os=centos53computeA

## To submit type: qsub x.sh

# If not an interactive job (i.e. -I), then cd into the directory where
# I typed qsub.
if [ "$PBS_ENVIRONMENT" != "PBS_INTERACTIVE" ]; then
  if [ -n "$PBS_O_WORKDIR" ]; then
    cd $PBS_O_WORKDIR
  fi
fi

# the input file is typically named something like "gamesjob.inp"
# so the script will be run like "$SCINET_RUNGMS gamessjob 00 8 8"

# find /scratch/mzd/gamess-scratch -type f -name ${NAME:-safety_net}\* -exec /bin/rm {} \;

# load the gamess module if not in .bashrc already
# actually, it MUST be in .bashrc
# module load gamess

# run the program

awk '/\ $VIB/{p=1}p;END{print " $END"}' /scratch/mzd/rungms/$NAME.rst >> job_name_restart.inp


Last edited by marcozd; 07-06-2010 at 11:34 AM..
# 16  
Old 07-05-2010
Last line syntax-wise is OK. I don't know if it will work, as I have zero experience with that (or any) computing cluster solution.
# 17  
Old 07-05-2010
OK. I tried to run it an d it gave me this error. I realize you may not be able to help with this, but I am going to try anyway! It is so close!

I get:

Code:
awk: cmd. line:1 fatal: cannot open file '/scratch/mzd/gamess-scratch/.rst' for reading (No such file or directory)

Any ideas?
# 18  
Old 07-05-2010
It looks like $NAME variable is empty. Did you pass variable value while executing script? Like
Code:
#qsub x.sh -v NAME=job_name

?
This User Gave Thanks to bartus11 For This Post:
# 19  
Old 07-06-2010
MySQL

Hey.

SOrry for the late resposnse. I did indeed pass the variable when I executed the script.

I am calling it "vib.sh"

It is only a problem with the variable though I don't know why. If I don not use the variable and define the files explicitly by their file names and locations, then the script works fine.

It is only not working with the $NAME variable.

Thanks again for all of your help.

---------- Post updated 07-06-10 at 12:23 PM ---------- Previous update was 07-05-10 at 07:12 PM ----------

I figured out why it was not working. Turns out I was defining my variables in an incorrect fashion.

Here is the working script:

Code:
#!/bin/bash
# script to add vibrational data for a hessian restart

awk '/\$VIB/{p=1}p;END{print " $END"}' /scratch/mzd/gamess-scratch/$NAME1.rst >> $NAME2.inp

and to run it, I type in:

Quote:
NAME1=job_name NAME2=job_name_restart ./vib.sh
or if I use the queue on the cluster

Quote:
qsub vib.sh -v NAME1=job_name,NAME2=job_name_restart
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to append multiple text files into one file based on pattern present in filaname

Hi All-I am new to Unix , I need to write a script. Can someone help me with a requirement where I have list of files in a directory, I want to Merge the files if a pattern of string matches in filenames? AAAL_555A_ORANGE1_F190404.TXT AAAL_555A_ORANGE2_F190404.TXT AAAL_555A_ORANGE3_F190404.TXT... (6 Replies)
Discussion started by: Shankar455
6 Replies

2. UNIX for Beginners Questions & Answers

awk to update file with partial matching line in another file and append text

In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

Need comand or script for append text after searching for the desired string

Hi all, i have a generated report in unix in the following command like input.txt 47.85,10 0124,42.35,8 0125,3.5,2 the input file format is fixed I need the my output file with append text as below output.txt 0124 amount:42.35 0125 amount:3.5 0124 count : 8 0125... (34 Replies)
Discussion started by: hemanthsaikumar
34 Replies

4. Shell Programming and Scripting

Needed shell script to append desired text to each line in a file

Hi, I had generated a report in my tool as followsoutput.txt 43.35 9 i needed the script to generate a new file like below i want to append the text to each of these lines of my filenewoutputfile.txt should be Total Amount : 43.35 Record Count:9 Regards, Vasa Saikumar. ... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

5. Shell Programming and Scripting

How to append a text file?

i have to append a text file grep for a word, if found, put comment in starting of the line. here is an example cat test.sh bin/ksh Hello World Test Message :wq! search for "bin" word in test.sh file if found comment it out at starting of the line: Output as follows: #bin/ksh... (5 Replies)
Discussion started by: raghur77
5 Replies

6. Shell Programming and Scripting

Open the file and edit/append the text

Hi i have a file like this mailboxnum 20 filename <to subsitute> fileloaction /home/dd234/ filetype txt in a directory i have set of files for ex: TT45.1.2 TT45.1.3 TT45.1.4 . . in for loop i have to take this files and subsitute one by one ex: (1 Reply)
Discussion started by: greenworld123
1 Replies

7. Shell Programming and Scripting

Append Text in Result File Name

Hi Below command is returning the list of files which having this string "MTL_SYSTEM_ITEMS". find . -name "*"|xargs grep -il MTL_SYSTEM_ITEMS Ex: Above command is returing 2 files (Out of 10 files 2 files having this string). ./file1.txt and ./file2.txt Here I want to append... (3 Replies)
Discussion started by: balajiora
3 Replies

8. Shell Programming and Scripting

How to append text to the second line of a file

Say I have a text file like: 1 3 4 How would I use ksh to put the number '2' into the second line of that file? I'm using OpenBSD so the sed syntax might be a bit different (I have no idea how to use sed, though) (4 Replies)
Discussion started by: guitarscn
4 Replies

9. UNIX for Dummies Questions & Answers

append a text to a file every month

i have something like below in my SAS code and every month i need to append a text say 'ext.hlc_sum0906' near ext.hlc_sum0905 and next month after ext.hlc_sum0906 i need to append this 'ext.hlc_sum0907' and so on like that.. is it possible using SED or some other command in unix? %let... (1 Reply)
Discussion started by: depakjan
1 Replies

10. Shell Programming and Scripting

how to append text into a file.

I have a command stream that will parse down an ftp DIR listing of a remote directory and return the name of the newest file that I am interested in. The command is sed -e '/^d/d' sppay.listing |sed -n -e '/SPPAY/p'|sort -r -k 43M,45 -k 47,48 -k 50,54|sed -n -e '1p'|cut -c 56-99 and what it... (2 Replies)
Discussion started by: beilstwh
2 Replies
Login or Register to Ask a Question