Thank you very much for your valuable inputs and comments!. Appreciate all your help!
I had slight variation in the rules file when there is a rule for a field that do not exist in input, as well the 'Contains' requirement as below:
Rules file:
Input file:
I am getting error due to the extra Rule
, for which fieldx does not exist in Inpurt file.
Error message: "awk: Field is not correct. The input line number is 2. "
Appreciate your help to handle this.
After I deleted the "fieldx|{{|Equals|" record from Rules file, I am getting below output:
But, the expected output I need is :
The Rule for "fieldx" can be reported into Reject file saying it did not exist in input.
Any help is highly appreciated in dealing with these 2 scenarios.
Thank you!
Chand.
Chand,
I have rewritten the script to process multiple input files and allow fields specified in the rules file to be skipped if the field named in a rule does not appear as an input file's field header. (If this happens, a note will be included in the reject file as you requested stating that a rule is invalid.)
Making the script replace every occurrence of a search string rather than just the first occurrence was done by just changing a call to sub() to be a call to gsub(). I have expanded the shell portion of the script to support several options and provide a built-in man page. The in-line comments explaining what the script does have also been expanded in hopes that you will be able to make further enhancements yourself.
Note that the rule that you said should convert the input line:rc$$$21|rc#21|yyy|to:rc21|rc#21|yyy|, it won't do that because the rule in you rules file has two spaces in the replace field. Therefore, the result of applying that rule to every occurrence that matches will instead produce the output:
Because the script is so large now, I have attached it rather than including it in-line here. The name of the script is substitute, but to upload it I had to use the name substitute.sh. It is written as a Korn shell script that calls awk. You should be able to use a Bourne shell, or bash, as well as a Korn shell if you just change the first line of the script from #!/bin/kshto the path to your shell. (However, it won't work with csh or any of its variants.)
If you are on a Solaris system, use nawk or /usr/xpg4/bin/awk instead of awk.
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)