Sponsored Content
Top Forums Shell Programming and Scripting how to append a block of statements after another block in the file Post 302305678 by quirkasaurus on Thursday 9th of April 2009 01:27:41 PM
Old 04-09-2009
awesome solution, nobody8.

i'll present my solution, too, but just cause it's an interesting paradigm
that can be modified to do almost anything.

Code:
for file in `cat my_list_of_files_to_edit` ; do

vi +/"Safety check - do you really wish to run" $file << EOF
:/^fi
O#
openpipe tsdbdwn2
set -x
exec >> /tmp/tsdbdwn2.fifo 2>&1
#
^[:wq
EOF

done

where ^[ is actually the ESCAPE character.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

block of name value pair to db insert statements

Hi, I need to convert the following file into DB insert statements. $ cat input.txt START name=john id=123 date=12/1/09 END START name=sam id=4234 status=resigned date=12/1/08 END (2 Replies)
Discussion started by: vlinet
2 Replies

2. Shell Programming and Scripting

finding a block in a file and replace with another file block.

(1) Yes but how is this block different from the other 24? You will need this information in order to identify and replace this block correctly (out of the 25). Ans: The 1st line and last line of this block are unique from other block. The 1st line is “rem Subset Rows (&&tempName.*) and The... (1 Reply)
Discussion started by: Zaheer.mic
1 Replies

3. UNIX for Advanced & Expert Users

Deciding whether to get a buffer cache block or inode block

I was reading a book on UNIX internals "The design of the UNIX Operating system." There are two memory structures that are confusing me: 1) Buffer cache 2) Inode cache My questions are 1) Does a process get both buffer cache and Indoe cache allocated when it opens/creates a file? 2) if no,... (1 Reply)
Discussion started by: sreeharshasn
1 Replies

4. Shell Programming and Scripting

Grepping text block by block by using for loop

Hei buddies, Need ur help once again. I have a file which has bunch of lines which starts from a fixed pattern and ends with another fixed pattern. I want to make use of these fixed starting and ending patterns to select the bunch, one at a time. The input file is as follows. Hi welcome... (12 Replies)
Discussion started by: anushree.a
12 Replies

5. UNIX for Advanced & Expert Users

Move a block of lines to file if string found in the block.

I have a "main" file which has blocks of data for each user defined by tags BEGIN and END. BEGIN ID_NUM:24879 USER:abc123 HOW:47M CMD1:xyz1 CMD2:arp2 STATE:active PROCESS:id60 END BEGIN ID_NUM:24880 USER:def123 HOW:4M CMD1:xyz1 CMD2:xyz2 STATE:running PROCESS:id64 END (7 Replies)
Discussion started by: grep_me
7 Replies

6. Shell Programming and Scripting

Printing a block of lines from a file, if that block does not contain two patterns using sed

I want to process a file block by block using sed, and if that block does not contain two patterns, then that complete block has to be printed. See below for the example data. ................................server 1............................... running process 1 running... (8 Replies)
Discussion started by: Kesavan
8 Replies

7. Shell Programming and Scripting

sed - append line after block

Hi, I posted in another section, but no reply yet. I have an ini file with sections denoted as follows (for example) blah=blah blee=blee bloo=bloo blur=blur blaa=blaa I have ksh script that needs to append a line ${line} to the end of section ${section} I saw this... (7 Replies)
Discussion started by: andyatit
7 Replies

8. Shell Programming and Scripting

How to append to array within conditional block in ksh/korn shell?

Hi, I have one array created and some values are there in ksh. I want to append some other values to it based on some condition in if statement. #!/bin/ksh echo "---------------------------------------------------" set -A ipaddr_arr $(egrep -v '^#|^::|^$' /etc/hosts |awk '{print $1}'... (2 Replies)
Discussion started by: sanzee007
2 Replies

9. Shell Programming and Scripting

Get values block by block in same file

I have a file say "SAMPLE.txt" with following content, P1 10,9:6/123456 P2 blah blah P1 10,9:5/98765 P2 blah blah P1 blah blah P2 I want a output file say "RESULT.txt" as, Value1:123456 Value2:98765 Value3:NULL (17 Replies)
Discussion started by: garvit184
17 Replies

10. UNIX for Dummies Questions & Answers

Add a block of code at the end of a specific block

I need to search for a block with the starting pattern say "tabId": "table_1", and ending pattern say "]" and then add a few lines before "]" "block1":"block_111" "tabId": "table_1", "title":"My title" ..... .... }] how do I achieve it using awk and sed. Thanks, Lakshmi (3 Replies)
Discussion started by: Lakshmikumari
3 Replies
bart_rules(4)							   File Formats 						     bart_rules(4)

NAME
bart_rules - bart rules file DESCRIPTION
The bart_rules file is a text file that is used by the bart(1M) command. The rules file determines which files to validate and which file attributes of those files to ignore. Some lines are ignored by the manifest comparison tool. Ignored lines include blank lines, lines that consist only of white space, and com- ments that begin with #. The rules file supports three directives: CHECK, IGNORE, and a subtree directive, which is an absolute path name and optional pattern matching modifiers. Each CHECK, IGNORE, and subtree directive must be on a separate line. Bart supports continuation of long lines using a backslash (). The rules file uses the directives to create logical blocks. Syntax The syntax for the rules file is as follows: [IGNORE attribute...]* [CHECK] [attribute...]* subtree1 [pattern...]* [IGNORE attribute...]* [CHECK] [attribute...]* subtree2 [pattern...]* subtree3 [pattern...]* subtree4 [pattern...]* [IGNORE attribute...]* [CHECK] [attribute...]* ... Rule Blocks Rule blocks are composed of statements that are created by using directives and arguments. There are three types of blocks: Global Block The first block in the file. The block is considered ``global'' if it specifies CHECK and IGNORE statements, but no previous subtree statement. A global block pertains to all subsequent blocks. Local block A block that specifies CHECK and IGNORE statements as well as a subtree directive. The rules in this block pertain to files and directories found in the specified subtree. Heir block A block that contains a null CHECK statement, no arguments. This block inherits the global CHECK statements and IGNORE statements. The order in which CHECK and IGNORE statements appear in blocks is important. The bart command processes CHECK and IGNORE statements in the order in which they are read, with later statements overriding earlier statements. Subtree specifications must appear one per line. Each specification must begin with an absolute path name. Optionally, each specification can be followed by pattern-matching arguments. When a file system being tracked belongs to more than one subtree directive, bart performs the following resolution steps: o Applies the CHECK and IGNORE statements set in the global block. Note that all CHECK and IGNORE statements are processed in order. o Finds the last subtree directive that matches the file. o Processes the CHECK and IGNORE statements that belong to the last matching subtree directive. These statements are processed in the order in which they are read, overriding global settings. Pattern Matching Statements There are two types of pattern matching statements AND For a given subtree directive, all pattern matching statements are logically ANDed with the subtree. Patterns have the following syntax: o Wildcards are permitted for both the subtree and pattern matching statements. o The exclamation point (!) character represents logical NOT. o A pattern that terminates with a slash is a subtree. The absence of a slash indicates that the pattern is not a directory. The subtree itself does not require an end slash. For example, the following subtree example includes the contents of /home/nickiso/src except for object files, core files, and all of the SCCS subtrees. Note that directory names that terminate with .o and directories named core are not excluded because the patterns specified do not terminate with /. /home/nickiso/src !*.o !core !SCCS/ CHECK all OR Group multiple subtree directives together. Such subtree directives are logically ORed together. /home/nickiso/src !*.o !core /home/nickiso/Mail /home/nickiso/docs *.sdw CHECK all IGNORE mtime lnmtime dirmtime The files included in the previous example are as follows: o Everything under /home/nickiso/src except for *.o and core files o Everything under /home/nickiso/Mail o All files under /home/nickiso/docs that end in *.sdw For these files, all attributes are checked except for modification times. File Attributes The bart command uses CHECK and IGNORE statements to define which attributes to track or ignore. Each attribute has an associated keyword. The attribute keywords are as follows: acl ACL attributes for the file. For a file with ACL attributes, this field contains the output from acltotext(). all All attributes. contents Checksum value of the file. This attribute is only specified for regular files. If you turn off context checking or if checksums cannot be computed, the value of this field is -. dest Destination of a symbolic link. devnode Value of the device node. This attribute is for character device files and block device files only. dirmtime Modification time in seconds since 00:00:00 UTC, January 1, 1970 for directories. gid Numerical group ID of the owner of this entry. lnmtime Creation time for links. mode Octal number that represents the permissions of the file. mtime Modification time in seconds since 00:00:00 UTC, January 1, 1970 for files. size File size in bytes. type Type of file. uid Numerical user ID of the owner of this entry. EXAMPLES
Example 1: Sample Rules File The following is a sample rules file: # Global rules, track everything except dirmtime. CHECK all IGNORE dirmtime # The files in /data* are expected to change, so don't bother # tracking the attributes expected to change. # Furthermore, by specifying ``IGNORE contents,'' you save # time and resources. /data* IGNORE contents mtime size /home/nickiso f* bar/ IGNORE acl # For /usr, apply the global rules. /usr CHECK # Note: Since /usr/tmp follows the /usr block, the /usr/tmp # subtree is subjected to the ``IGNORE all.'' /usr/tmp /home/nickiso *.o /home/nickiso core /home/nickiso/proto IGNORE all The following files are cataloged based on the sample rules file: o All attributes, except for dirmtime, mtime, size, and contents, are tracked for files under the /data* subtrees. o Files under the /usr subtree, except for /usr/tmp, are cataloged by using the global rules. o If the /home/nickiso/foo.c file exists, its attributes, except for acl and dirmtime, are cataloged. o All .o and core files under /home/nickiso, as well as the /home/nickiso/proto and /usr/tmp subtrees, are ignored. o If the /home/nickiso/bar/foo.o file exists, it is ignored because it is subject to the last block. SEE ALSO
bart(1M), bart_manifest(4), attributes(5) SunOS 5.10 9 Sep 2003 bart_rules(4)
All times are GMT -4. The time now is 01:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy