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
# 8  
Old 07-05-2010
What does it show:
Code:
awk '/\$VIB/' job_name.rst

# 9  
Old 07-05-2010
It shows " $VIB"
# 10  
Old 07-05-2010
Then it has to work. Try again this code:
Code:
awk '/\$VIB/{p=1}p;END{print "$END"}' job_name.rst

Note, that there is no "^" in that command.
This User Gave Thanks to bartus11 For This Post:
# 11  
Old 07-05-2010
Computer

When I enter that command I get all of the text between the $VIB and it has added $END at the end!Smilie

I then used the second command you suggested (without the "^" character and it also works perfectly!Smilie

Thanks so much! I realize I am asking a lot, but is there a way to make this into a script with variables?

I am using a computing cluster, and I use a bash script to submit my jobs. It looks like this:

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

/scratch/mzd/rungms $NAME 00 8 8 >& $NAME.log

So when I submit a the input file "job_name.inp", I enter something like

Code:
#qsub gms_8.sh -N job_name -v NAME=job_name

What I was wondering is if there is a way to make a shell script using your amazingly helpful awk command but with the variable "$NAME" for the file name?
# 12  
Old 07-05-2010
Sure. This should work in your script:
Code:
awk '/\$VIB/{p=1}p;END{print "$END"}' $NAME >> job_name_restart.inp

# 13  
Old 07-05-2010
Power

Quote:
Originally Posted by bartus11
Sure. This should work in your script:
Code:
awk '/\$VIB/{p=1}p;END{print "$END"}' $NAME >> job_name_restart.inp

Where do I put this? Do I need to make a new script or simply replace the last line?

I am a bit confused as the "job_name.rst" file is always located in /scratch/mzd/gamess-scratch/. Don't I need to specify that in my script somewhere?
# 14  
Old 07-05-2010
Well, it depends when is your ".rst" file generated. If it is created after last command in your script is finished, then I think that AWK code should go after it. As for paths and filenames, I won't help you much here.
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