Please ignore the first question.
still I would like to know what might be the possbile reason that the second and third "if" can not be executed while the first match (first if ) evidently doesn't hold.
Hey, all
I have been struggling with problem for quite a while, any hints of librating me from the fight will be highly appreciated.
first there is a file "pool", the first col is something with will be matched by some key
WorldComInc WorldCom, Inc.
second there is file "key_trace"...
Hi,
thanks,
PHV and feherke.
I do agree with feherke that the this thread is somewhat off-topic, I assume people who has expertise on awk will also be familiar with sed.
Anyway, the task can be pretty decently done with awk.
Best
Hi, all
suppose I have following txt file "people"
Tim US
Xue CHN
Will US
Tom US
Yong CHN
if I work with a sedscript as following:
/US$/ {
s//USA/
w us.origin_1
}
then following code works
sed -n -f sedscript people
However, its oneliner version as below doesn't
sed '/US$/ {s//USA/; w...
suppose your data file is named "myfile" and an unique number at field 4 correspond to a unique name, do this
awk 'BEGIN{FS=OFS=","} NR==FNR {namecode[$4]=$5;next} {print $1,$2,$3,namecode[$1],namecode[$1]}' myfile myfile
tested and works!
will27
Hi, feherke
Thank you for your tip and sorry for the confusion, I did some modification to fit the pseudo example when wrote this post but not careful enough.
your code is succinct and elegant, howover, I am still wondering what's the problem with my code as following.
awk...
Hi, all
The data is like following:
############## data ####################
time name price
20050616 company2 32
19900112 company1 39
19980223 company2 44
20060523 company1 55
############# job to be done ################
the job is simple, find the starting...
thanks, futurelet
the code works, the biggest problem turns out that the key field in keyfile contains "", this is disastrous, "" alway get a match.
will
thanks for the follow-up clarifications, and it is very helpful.
one more question to futurelet, hope this will not bother you.
I tried to extend your example to array, and apply them to follwoing two dataset(they are only a very small excerpts from the original dataset):
get some...
Hi, all
thanks for the answer.
first I am sorry the code is kind of confusing. what I really intend to do at the first line of the script is to read the first file. p5wizard, thanks for the answer, I did the same, it won't work.
futruelet's code works great.thank you!
I would appreciate it if...
Hi, all
I have been trying to find a way to pass parameters into regular expression, failed, so I am back.
for example, I have following two files:
# firstfile
USA US United_States_of_America
# secondfile
x company USA
US y Company
xyz United_States_of_America
what I want is to pass...
Dear feherke
I really thank you so much and sorry for this late gratitude.
Your code is several magnitude faster than mine and, most importantly, it spells out results as I want.
However, I am still wondering where is the problem of my original code (I know it's ugly and will stick to the...
Hi, all
I get many keys to extract records in other files. However, following scripts doesn't spell out what I expected.
Both the keyfile and to be extracted files are tab dlimited.
# keys in three column
for keycol in 1 2 3
do
# creat a vector...
Dear all
I am sure this is a simple quesiton for most people visiting this forum.
the question in detail is as following:
A data file with unconstant NF, the fields I want to reserve is field 1 to field (NF-1), they should be printed out on the same row. for example
thank you for your kind...
Dear all
What follows is a simple awk program with a shell wrapper. The problem is sometimes it works fine and sometime it won't.
##########################################################
for ((i=1990;i<=2006;i++))
do
awk 'BEGIN{FS=OFS="\t"} {if ($2==m) print $1,$3,$4}' m=$i GI> tmpGI
awk...
Hi,PH
this time it works, thanks for all your help.
One last question, this might have something to do with my own code.
what's the default for the array to subscrbe itself? I printed out all the subs, they looks the same as in the key on all dimensions (of course the unque elements of the...
Hi, PHV
I cut and pasted the code, the problem is no output at all!
when apply the same code to "wf1" and "wf2", the output is as following
meta weight data country desc meta weight data country desc
only title, nothing else.
I do think your code is right, I checked all...
Thanks for your quick response, PHV
however, it won't work, I also tried some alternative of your codes, get nowhere.
maybe I should simply try unix "join", though it is not wise to sort the file.
will
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.