Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Shell script for search and replace by field Post 302707967 by Don Cragun on Sunday 30th of September 2012 03:31:33 PM
Old 09-30-2012
Please use code tags when you post examples of file contents and program fragments!

What are the field separators in your input files and in your rules file? What field separator do you want in the output and reject files?

Am I correct in assuming that the reject file is supposed to contain the original contents of every line that was changed by one or more rules in the rules file while producing the output file?

What is the distinction between the conditions "Equals" (or "equals") and "contains" (or "contauns")? It looks like if the character(s) found in the search field in the rules file are found in the field specified by the field named in the rules file for either condition, the content of the replace field in the corresponding line in the rules file replaces what was matched by the search field.

Am I correct in assuming that the "contauns" was a typo?

Is the contents of the condition column supposed to be case insensitive or was the "Equals" also a typo?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search and replace dynamic data in a shell script

Hi, I have a file that looks something like this: ... 0,6,256,87,0,0,0,1187443420 0,6,438,37,0,0,0,1187443380 0,2,0,0,0,10,0,1197140320 0,3,0,0,0,10,0,1197140875 0,2,0,0,0,23,0,1197140332 0,3,0,0,0,23,0,1197140437 0,2,0,0,0,17,0,1197140447 0,3,0,0,0,17,0,1197140543... (8 Replies)
Discussion started by: csejl
8 Replies

2. Shell Programming and Scripting

awk search and replace field

I am writing a c++ program that has many calls of pow(input,2). I now realize that this is slowing down the program and these all should be input * input for greater speed. There should be a simple way of doing this replacement throughout my file with awk, but I am not very familiar with awk.... (2 Replies)
Discussion started by: bluejayek
2 Replies

3. Shell Programming and Scripting

Perl - search and replace a particular field

Hi, I have a file having around 30 records. Each record has 5 fields delimited by PIPE. Few records in the file having Junk characters in the field2 and field4. I found the junk charcter and I tested it and replace the junk with space with the command below perl -i -p -e "s/\x00/ /g"... (1 Reply)
Discussion started by: ramkrix
1 Replies

4. Shell Programming and Scripting

Search duplicate field and replace one of them with new value

Dear All, I have file with 4 columns: 1 AA 0 21 2 BB 0 31 3 AA 0 21 4 CC 0 41 I would like to find the duplicate record based on column 2 and replace the 4th column of the duplicate by a new value. So, the output will be: 1 AA 0 21 2 BB 0 31 3 AA 0 -21 4 CC 0 41 Any suggestions... (3 Replies)
Discussion started by: ezhil01
3 Replies

5. Shell Programming and Scripting

Search a string,get line and replace with second field

Hi, I need to search for source path in file2 , as per file1 and if found get the next line and take the field value and put it in URL value of file1. In file1, NF is not same for all the lines. file1: <type source="/home/USER/Desktop" Dest="/home/USER/DIR1/Desktop" URL="ssh/path"/> <type... (8 Replies)
Discussion started by: greet_sed
8 Replies

6. Shell Programming and Scripting

Search and replace field?

I have 2 files A.txt and B.txt A.txt 3 fields and separate by a comma some,thing,florida any1,thing1,california some2,thing2,dallas just,fun,kansas B.txt has 8 fields and separate by a comma what,ever,florida-state,,,,,, some,one,dallas_state,,,,,, You will see 3rd fields are the... (5 Replies)
Discussion started by: sabercats
5 Replies

7. Shell Programming and Scripting

awk search and replace in a targeted field instead of $0

Hi I would like to apply this gawk command: gawk '{$0=gensub(/\y+\y/,"","g"); print}' file not to the whole $0 but just to the part of $0 that is between: (a number)"> and </mrk> Is it possible? thanks for your help. (4 Replies)
Discussion started by: louisJ
4 Replies

8. Shell Programming and Scripting

Search field in text file and replace value

Hi there, First of all this is my first post here. Thank you in advance for your help. What I am trying to do is the following. I have a text file where each field of each row is separated by a tabulator. Looks like this: ATOM 1 N HSE A 26 3.033 -10.429 -2.262 1.00 17.07 ... (8 Replies)
Discussion started by: doom4
8 Replies

9. Shell Programming and Scripting

Search for a value and replace other field in the same set

Hello friends, I have huge file with many sets where each "set" has few lines and each set always begins with "Set" in Sq brackets as shown above. # cat file1 (2 Replies)
Discussion started by: magnus29
2 Replies

10. UNIX for Dummies Questions & Answers

Search and replace the last field

Hi All, Seeking for your assistance on how to search and replace the last field/column. please see sample below: inputfile1.csv ="8923523434",="543623534"="afd23535623",="100"="200" ="8923523431",="543623536"="afd23535626",="101"="201"... (3 Replies)
Discussion started by: poginiks
3 Replies
sesearch(1)						      General Commands Manual						       sesearch(1)

NAME
sesearch - SELinux policy query tool SYNOPSIS
sesearch [OPTIONS] RULE_TYPE [RULE_TYPE ...] [EXPRESSION] [POLICY ...] DESCRIPTION
sesearch allows the user to search the rules in a SELinux policy. POLICY
sesearch supports loading a SELinux policy in one of four formats. source A single text file containing policy source for versions 12 through 21. This file is usually named policy.conf. binary A single file containing a monolithic kernel binary policy for versions 15 through 21. This file is usually named by version - for example, policy.20. modular A list of policy packages each containing a loadable policy module. The first module listed must be a base module. policy list A single text file containing all the information needed to load a policy, usually exported by SETools graphical utilities. If no policy file is provided, sesearch will search for the system default policy: checking first for a source policy, next for a binary policy matching the running kernel's preferred version, and finally for the highest version that can be found. In the latter case, the policy will be downgraded to match the running system. If no policy can be found, sesearch will print an error message and exit. RULE TYPE OPTIONS
sesearch is capable of searching multiple types of rules. At least one of the following must be provided to specify the desired type(s) of rules to search. -A, --allow Search for allow rules. --neverallow Search for neverallow rules. --auditallow Search for auditallow rules. --dontaudit Search for dontaudit rules. -T, --type Search for type_transition, type_member, and type_change rules. --role_allow Search for role allow rules. --role_trans Search for role_transition rules. --range_trans Search for range_transition rules. --all Search all rule types. EXPRESSIONS
The user may specify an expression containing values for a given field(s) in a rule. Only those fields applicable to a given rule type will be used; all other fields will be ignored. (For example, type_transition rules will ignore the permissions field.) If no expression is specified or if none of the specified fields apply to a given rule type, all rules of that type are considered to match the expression. -s NAME, --source=NAME Find rules with type/attribute NAME as their source. -t NAME, --target=NAME Find rules with type/attribute NAME as their target. --role_source=NAME Find rules with role NAME as their source. --role_target=NAME Find rules with role NAME as their target. -c NAME, --class=NAME Find rules with class NAME as their object class. -p P1[,P2,...] --perm=P1[,P2...] Find rules with at least one of the specified permissions. Multiple permissions may be specified as a comma separated list; it is recommended that this list be quoted for shells that interpret comma as a special character. -b NAME, --bool=NAME Find conditional rules with NAME in their conditional expression. This option will include rules in both the true and false lists of the conditional. OPTIONS
The following additional options exist to modify how the search is performed and the amount of information printed for each result. -d, --direct Normally rules are matched using the type given or any of that type's attributes (or an attribute's types). This "indirect" match- ing also considers types used in complemented sets, the special set "*", and the special target "self". When the direct flag is given, matching is done literally. The rule must explicitly contain the given type (or attribute) for it to be returned. -R, --regex Use regular expressions to match symbol names. By default only exact string matches will be considered. -n, --linenum Print the line number for each rule. This option is ignored if using the --semantic option or if line numbers are not available for the given policy. -S, --semantic Search rules semantically instead of syntactically. This option is implied for policies for which syntactic rules are not available. -C, --show_cond Print the conditional expression and state for all conditional rules found. This option has no effect on unconditional rules. -h, --help Print help information and exit. -V, --version Print version information and exit. AUTHOR
This manual page was written by Jeremy A. Mowery <jmowery@tresys.com>. COPYRIGHT
Copyright(C) 2003-2008 Tresys Technology, LLC BUGS
Please report bugs via an email to setools-bugs@tresys.com. SEE ALSO
seinfo(1), apol(1) sesearch(1)
All times are GMT -4. The time now is 07:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy