sdf
January 24, 2012, 3:50pm
1
Need to remove rest of line after the equals sign on search pattern from the searchfile. Can anybody help. Couldn't find any similar example in the forum:
infile:
64_1535: Delm. = 86 var, aaga
64_1535: Fran. = 57 ex. ccc
64_1639: Feb. = 26 (link). def
64_1817: mar. = 3/4. drz
64_1890: Sc. = 4420.
64_1901: No. = 254. kjkj
64_1902: No. = 273
64_1902: Fr. = 793. kle
64_1903: Ke. = 2. sesg
searchfile:
aaga
ccc
def
drz
kjkj
kle
sesg
desired output (with or without the punctuation at the end):
64_1535: Delm. = 86 var
64_1535: Fran. = 57 ex
64_1639: Feb. = 26 (link)
64_1817: mar. = 3/4
64_1890: Sc. = 4420
64_1901: No. = 254
64_1902: No. = 273
64_1902: Fr. = 793
64_1903: Ke. = 2
Sorry but example isn't detailed enough can you supply desired output from this input:
64_1535: No equals here aaga
..........................
64_1535: Delm. = 86 var, aaga, ccc
64_1535: Fran. = 57 ex.,, ccc
64_1639: ccc
64_1817: mar. = 3/4....
64_1890: Sc. = 4420 mar. = 3/4 aag
64_1891: Dec. = 420 not_in_search ccc
64_1901: No. = 254 kjkj
awk '{gsub(/[,.].*/, "",$2)}1' FS="=" OFS="=" infile
1 Like
See sdf, you will get solutions like the above if you don't supply enough info on what you want.
Sorry, just caught me on a bad day I suppose.
I must admit I was very tempted to supply the following myself:
sed 's/[.,][^=.,]*$//' infile
1 Like
sdf
January 25, 2012, 6:56am
7
Thanks for the suggestion. I was more looking for someting like this:
awk 'BEGIN{FS=OFS="="} NR==FNR {arr[$0]; next}{gsub(/[arr].*/, "",$2)}1' searchfile infile
Can't get gsub to work with an array as a search pattern.
sed 's/^ *//;s/ *$//' searchfile > searchfile.new
sed 's/^ *//;s/ *$//' infile > infile.new
If only list the line in searchfile
awk 'BEGIN{FS=OFS="="} NR==FNR{arr[$1];next}
{l=split($0,a," "); if (a[l] in arr) {gsub(/[,.].*/, "",$2);print}}' searchfile.new infile.new
list all
awk 'BEGIN{FS=OFS="="} NR==FNR{arr[$1];next}
{l=split($0,a," "); if (a[l] in arr) {gsub(/[,.].*/, "",$2)}}1' searchfile.new infile.new