Sponsored Content
Top Forums Shell Programming and Scripting Append text from one file to another based on a search from the end of a document Post 302464646 by marcozd on Wednesday 20th of October 2010 04:10:07 PM
Old 10-20-2010
Question Append text from one file to another based on a search from the end of a document

Hi all,

I have output files that are all text files with various different extensions.

So, if I submit the input file "job_name.inp", when it finishes I get an output file "job_name.dat". A typical input file looks something like this:

Code:
 $CONTRL SCFTYP=RHF RUNTYP=ENERGY MAXIT=199 MULT=1 NOSYM=1
  $END
 $SYSTEM TIMLIM=2800 MWORDS=20 MEMDDI=50 PARALL=.TRUE. $END
 $GUESS GUESS=HCORE $END
 $SCF DIRSCF=.TRUE. FDIFF=.f. DIIS=.T. SOSCF=.F. DAMP=.T. $END
 $STATPT OPTTOL=0.00001 NSTEP=500  $END
 $FORCE TEMP=298.15 PURIFY=.t. PROJCT=.t. $END
 $DATA
 MoX6
C1
MOLYBDENUM 42.0     -0.0064896473      0.0000000000     -0.0299719236
S   3
  1      2.3610000             -0.9121760        
  2      1.3090000              1.1477453        
  3      0.4500000              0.6097109        
S   4
  1      2.3610000              0.8139259        
  2      1.3090000             -1.1360084        
  3      0.4500000             -1.1611592        
  4      0.1681000              1.0064786        
S   1
  1      0.0423000              1.0000000        
P   3
  1      4.8950000             -0.0908258        
  2      1.0440000              0.7042899        
  3      0.3877000              0.3973179        
P   2
  1      0.4995000             -0.1081945        
  2      0.0780000              1.0368093        
P   1
  1      0.0247000              1.0000000        
D   3
  1      2.9930000              0.0527063        
  2      1.0630000              0.5003907        
  3      0.3721000              0.5794024        
D   1
  1      0.1178000              1.0000000        
 
 $END

To run other types of jobs, I need to extract and append a portion of text that is in the "job_name.dat" file directly at the end of the text in the "job_name.inp" file directly below the "$END".

The text that needs to be appended is sandwiched between a line that contains only "$HESS" (which indicates the begining of the block of text that needs to be appended) and a line that contains only "$END".

Here is a shortened version of what it looks like:

Code:
 $HESS
ENERGY IS     -564.2186882597 E(NUC) IS      515.5174532336
 1  1 2.81829118E-01 1.96516215E-02 4.20602780E-02-4.88781528E-02 1.17369706E-02
 1  2-2.64287926E-02-7.58478386E-02-2.07409567E-03-1.79893671E-02-4.10847462E-02
 1  3 4.12539079E-03-1.47014988E-03-9.06341578E-02-1.93280378E-02 1.03405906E-02
 1  4-1.80442057E-02-2.76602476E-02 4.37651343E-03 1.11643572E-02 3.21356156E-03
.
.
.
$END

The trouble is that there are a number of these blocks of text that are delineated by "$HESS" and "$END".

The number of "$HESS" blocks of text varies between files unfortunately. The correct block is the very last one in the "job_input.dat" file.

Is there a way to use maybe awk for this but search backwards from the end of the document up?

Thanks in advance for any help with this!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append a field to the end of each line of a file based on searching another file.

Hi All, I have two comma separated value(CSV) files, say FileA and FileB. The contents looks like that shown below. FileA EmpNo,Name,Age,Sex, 1000,ABC,23,M, 1001,DES,24,F, ... (2 Replies)
Discussion started by: ultimate
2 Replies

2. Shell Programming and Scripting

Append text at end of the first line in a file

Hi I need to append some text @ end of the first line in a file. like myfile.txt list = a,b,c list.a=some.. I give the arg "d" . now it append at end of first line list=a,b,c,d list.a=some... Please help me out this (7 Replies)
Discussion started by: catgovind
7 Replies

3. Shell Programming and Scripting

search directory-find files-append at end of line

Hi, I have a command "get_data" with some parameters in few *.text files of a directory. I want to first find those files that contain this command and then append the following parameter to the end of the command. example of an entry in the file :- get_data -x -m50 /etc/web/getid this... (1 Reply)
Discussion started by: PrasannaKS
1 Replies

4. Shell Programming and Scripting

append some text message at the end of the file

Hi All, Please tell me how to append some text message at the end of the file. "File too large to view" example: xyz.log contains hhhhhhhhhhh hhhhhhjjjjjjjjj jjjjjjjjjjjjjjjjjjjjjj "File too large to view" Please advice (3 Replies)
Discussion started by: rajeshorpu
3 Replies

5. UNIX for Dummies Questions & Answers

How can I append a text at end of file after displaying the file

I have a file "sample.txt" with the content as below: Hi This is a Sample Text. I need a single command using cat which serve the following purpose. 1.display the contents of sample.txt 2.append some text to it 3. and then exit But, all should be served by a sinle command.:confused: (1 Reply)
Discussion started by: g.ashok
1 Replies

6. Shell Programming and Scripting

Append the text file with comma at the end of every word

Hi folks, Using shell, I am trying the append comma to every line of text. the requirement is like, I have to open the txt file in unix and read line by line and should add comma at the end of every word to make it single line txt file ------- abc@gmail.com bcd@gmail.com... (7 Replies)
Discussion started by: giridhar276
7 Replies

7. Shell Programming and Scripting

Search for a string, then append character to end of that line only

I have 2 files that I am working with $ cat file1 server1 server3 server5 server6 server8 $ cat file2 server1;Solaris; server2; SLES; server3;Linux; server4; Solaris; server5;SLES; server6;SLES; server7;Solaris; server8;Linux; (1 Reply)
Discussion started by: snoman1
1 Replies

8. Shell Programming and Scripting

To append new data at the end of each line based on substring of last column

Hi guys, I need to append new data at the end of each line of the files. This new data is based on substring (3rd fields) of last column. Input file xxx.csv: U1234|1-5X|orange|1-5X|Act|1-5X|0.1 /sac/orange 12345 0 U5678|1-7X|grape|1-7X|Act|1-7X|0.1 /sac/grape 5678 0... (5 Replies)
Discussion started by: null7
5 Replies

9. Shell Programming and Scripting

sed - go to file and search a part and set at the end text

Hello, i hope the titel is okay. I want to edit a line in /etc/arno-iptables-firewall/firewall.conf So the Line can contains: OPEN_TCP="436, 25, 80, 110, 143, 443, 465, 587, 993, 995, 21, 20" i want to search in this line: OPEN_TCP="*, *, 80, *, *, 443, *, *, *, *" and i want to... (11 Replies)
Discussion started by: tJAdASwIRDESSEI
11 Replies

10. 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
CONDOR_QSUB(1)							   User Commands						    CONDOR_QSUB(1)

NAME
condor_qsub - minimalistic qsub emulation for Condor SYNOPSIS
condor_qsub [OPTIONS] [<command> [<command_args>]] DESCRIPTION
Minimalistic emulation of SGE's qsub for Condor. The primary purpose of this emulation is to allow SGE-style submission of dependent jobs without the need to specify the full dependency graph at submission time. This implementation is neither as efficient as Condor's DAGMan, nor as functional as SGE's qsub/qalter. It merely serves as a minimal adaptor to be able to use software original written to interact with SGE in a Condor pool. In general condor_qsub behaves just like qsub. However, only a fraction of the original functionality is available. The following list of options only describes the differences in the behavior of SGE's qsub and this emulation. Qsub options not listed here are not supported. OPTIONS
-b <y|n> If 'y', command and arguments given on the command line are wrapped into a shell script which is then submitted to Condor. --condor-keep-files This is a non-SGE option. If given, it will prevent condor_qsub from deleting temporary files (generated submit files, sentinel jobs). This is mostly useful for debugging. -cwd If given, this option will cause the 'initialdir' value in the Condor submit file to be set to the current directory. -e <filename|path> Name of the file to contain the STDERR output of the job. By default this will be job_name.ejob_id[.task_id]. If an existing direc- tory is specified, the file will be placed inside this directory using the default schema for the filename. -h,--help Print usage summary and option list. -hold_jid <jid> If given, the job will be submitted in 'hold' state. Along with the actual job a 'sentinel' job will be submitted to Condor's local universe. This sentinel watches the specified job and releases the submitted job whenever the job has completed. The sentinel observes SGE's behavior to detect job exiting with code 100 and not start depedent job in this case. If a cluster id of an array job is given the dependent job will only be released after all individual jobs of a cluster have completed. -l <ressource spec> This option is currently ignored. -m <a|e|n><...> SGE's notification labels will be translated (approximately) into Condor's notifications states (Never, Error, Complete). -M <email> Added as 'notify_user' to the submit file. -N <jobname> Determines the default name of logfile (stdout, stderr). -o <filename|path> See -e option, but for a job's stdout. -p <int> Added a 'priority' to the submit file. -r <y|n> This option is currently ignored. -S <shell> Path to a shell binary for script execution. -shell <y|n> This option is currently ignored. -t <start>[-<stop>[:<step>]] Task ID specification for array job submissions. -q <queue name> This option is permanently ignored, as Condor doesn't have multiple queues. -V If given, 'getenv = True' is added to the submit file. --version Print version information and exit. This script is released under the Apache V2.0 License. It was written by Michael Hanke <michael.hanke@gmail.com>. condor_qsub 0.1 September 2012 CONDOR_QSUB(1)
All times are GMT -4. The time now is 02:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy