Search Results

Search: Posts Made By: jvoot
2,698
Posted By RavinderSingh13
Hello jvoot, Could you please try following....
Hello jvoot,

Could you please try following.

awk 'FNR==NR{a[$1]=$2;next} ($0 in a){print $1,a[$1]}' Input_file2 Input_file1


Output will be as follows.

ABC 123
DEF 345
XYZ 678
ABC...
2,719
Posted By Scrutinizer
Note that the behavior with the default FS=" " to...
Note that the behavior with the default FS=" " to skip and delimit using both blanks and newlines, used to be different in older Posix implementations, where blanks were used, but not newlines. mawk...
2,719
Posted By RudiC
Thanks, Don Cragun, for this clarification. ...
Thanks, Don Cragun, for this clarification.
Indeed, man gawk is way more explicit:


than is my man mawk: which I used in my above post. man gawk does not have this statement.
2,719
Posted By Don Cragun
This is a common misconception. With the input...
This is a common misconception. With the input we have been discussing in this thread:
PS028,006 [KJ <Cj>] [CM< <Pr>] [QWL TXNWNJ- <Ob>]
if that were the default ERE used for separating fields,...
2,719
Posted By RudiC
You are partly right, the field separator string...
You are partly right, the field separator string will be interpreted as a regex, and always. In Scrutinizers proposal (from which I stole shamelessly), he uses the bracket expression [][].
man...
2,719
Posted By Don Cragun
Hi jvoot, The standards clearly state that the...
Hi jvoot,
The standards clearly state that the value of the awk FS variable is an extended regular expression and it doesn't matter whether it is set using the -F option, using the -v option, using...
2,719
Posted By Don Cragun
OK... One final attempt... Based on your...
OK... One final attempt...

Based on your single sample latest input file, the following seems to do what you want and will at least show you lines where it wasn't able to match:
awk '
$1 ~...
2,719
Posted By RudiC
Try also awk -F"[][]" '/^ *PS.*<Ob>/ {sub(/...
Try also
awk -F"[][]" '/^ *PS.*<Ob>/ {sub(/ *<Ob>.*$/, ""); print $1, $NF}' file
PS028,005 ABC
PS028,005 XYZ
PS028,006 QWL TXNWNJ-
2,719
Posted By Don Cragun
One could still try: awk '$1 ~ /^PS/ {for(i=3;...
One could still try:
awk '$1 ~ /^PS/ {for(i=3; i<=NF; i++) if($i == "<Ob>]"){print $1,substr($(i-1), 2); next}}' file
without needing to use split() (unless I misunderstood and you changed your...
2,719
Posted By Scrutinizer
You are welcome, you do not need to use a...
You are welcome, you do not need to use a oneliner, BTW. You could do this:

INPUT |
awk ...
2,719
Posted By Don Cragun
In your sample data, the [string <0b>] always...
In your sample data, the [string <0b>] always appears at the end of the line that starts with <space>s immediately followed by PS. Is that also true in your real data? If it is, we can simplify the...
2,719
Posted By Scrutinizer
I wrote some additional approaches in my page....
I wrote some additional approaches in my page. And there was an extra variable (used for debugging) that I now removed in the first example. The is a space between the brackets in the field separator...
2,719
Posted By Scrutinizer
Hi, try using the square brackets as field...
Hi, try using the square brackets as field separators, for example:
awk -F '[][]' '
$1~/^[ \t]*PS/ {
for(i=2; i<=NF; i+=2)
if($i~/<Ob>/) {
split($i,F," ")
print $1...
1,677
Posted By Don Cragun
Hi jvoot, The code in the other thread I...
Hi jvoot,
The code in the other thread I pointed to in post #2 in this thread had to keep a counter of the number of lines in a file that had the same keys. As long as you treat both fields of a...
1,677
Posted By Scrutinizer
There is a leading space on all of the lines in...
There is a leading space on all of the lines in the samples of the second file.
If that is not there in the actual file, you could try:

awk '
NR==FNR {
A[$1,$2]
next
}
{
...
1,677
Posted By Don Cragun
Since you have multiple lines in File 1 with the...
Since you have multiple lines in File 1 with the same $1 values and different $2 values, there are a lot of similarities between the awk code needed to solve your problem and the problem that cmccabe...
1,677
Posted By MadeInGermany
You mean loop through the fields and each lookup...
You mean loop through the fields and each lookup in the array, like this?
if ($1 == "Lexeme") {
for (b=2; b<=NF; b++) if ($b in B) PR3 = 1
}Also, do you want to search <Co> in all the...
1,677
Posted By Don Cragun
The suggestions MadeInGermany provided you will...
The suggestions MadeInGermany provided you will work for your stated requirements.

But, when I look at you examples it seems that your requirements might be more stringent that what you have...
845
Posted By Scrutinizer
Hi, try: grep -A4 -f <(sed 's/ */.*/' File1)...
Hi, try:
grep -A4 -f <(sed 's/ */.*/' File1) File2
1,776
Posted By RudiC
So we have learned that posting correct specs AND...
So we have learned that posting correct specs AND samples (admittedly, ALSO reading them) saves time and effort on all sides. With a single * line separating blocks, the "STARONE" identification...
1,776
Posted By nezabudka
You can even do so NR==FNR {T[$1$2] ... ...
You can even do so
NR==FNR {T[$1$2]
...
if ($1$2 in T) PR1 = 1
1,776
Posted By RudiC
You are right, it's clearly written in your spec....
You are right, it's clearly written in your spec. He who can read... try


else {if (PR1 && PR2) {print BUF
print
...
1,776
Posted By RudiC
Let me try to paraphrase your request: In file2,...
Let me try to paraphrase your request: In file2, "blocks" (or "records"?) are delimited by a leading and a trailing * line. Whenever a block has a line whose $1,$2 matches any $1,$2 in file1, AND...
1,447
Posted By MadeInGermany
What behavior do you want with the following...
What behavior do you want with the following input file?
PS012,004 SP> 0 2 -1 -1 -1 12 -1 -1 -1 3 1 3 2 0 -1 -1 -1 -1 -1 -1 -1
PS012,004 PLG ...
1,447
Posted By MadeInGermany
I always prefer to have a state variable and a...
I always prefer to have a state variable and a store variable.
awk '
met==1 && $22=="503" && $4=="7" && $16=="2" {print save; print }
{ met=0 }
$16=="0" && $22=="-1" { save=$0; met=1 }
'
The {...
Showing results 1 to 25 of 57

 
All times are GMT -4. The time now is 08:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy