Duplication | awk | result


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Duplication | awk | result
# 22  
Old 06-13-2019
Of course you don't get any output as the $AAA shell variable is not expanded within single quotes. Why not use the standard awk interface as shown before? And, don't test $0 for a match but $2 only.
# 23  
Old 06-13-2019
Quote:
Originally Posted by RudiC
Of course you don't get any output as the $AAA shell variable is not expanded within single quotes. Why not use the standard awk interface as shown before? And, don't test $0 for a match but $2 only.
What you mean by single quotes? When I put "" on $AAA in awk '{ if ($0 ~ /"$AAA"/) sum += $3} END {print sum}' $i I am still getting no output.
As what you mean by awk standard interface as before? I tried using it but I need the output to print $3 column numerical values and not count how many ALA words there are. Any idea where I could read about this?
As for testing $2 instead of $0 I am getting zeros when I apply the awk command from before. I am reading and trying to implement it to change for checking if line has ALA and then take that lines 3rd column's numerical value and add it to other lines with ALA words and 3rd column's numerical values so I could have a sum of all ALA 3rd column numerical values. What should I read into or try to implement?
# 24  
Old 06-13-2019
Hi Aurimas,

Single quotes are ' characters. Within single quotes SHELL variables are not expanded, that only happens within double quotes ( " )

awk uses the -v var=value option as a way to pass outside parameters to the script.

See post #17
This User Gave Thanks to Scrutinizer For This Post:
# 25  
Old 06-13-2019
Quote:
Originally Posted by Scrutinizer
Hi Aurimas,

Single quotes are ' characters. Within single quotes SHELL variables are not expanded, that only happens within double quotes ( " )

awk uses the -v var=value option as a way to pass outside parameters to the script.

See post #17
Thanks Scrutinizer for clarifying it. I assumed single and double quotes have the same qualities, but was wrong.

I get the numerical values when I write awk '{ if ($0 ~ /'$AAA'/) sum += $3} END {print sum}' $i but am still getting nothing when I write awk -v AA="$AAA" '{ if ($0 ~ /AA/) sum += $3} END {print sum}' $i. Where might be the problem?

--- Post updated at 11:56 AM ---

Also for my code to be more precise I want that if ALA value duplicates as in the 1st and 2nd column it would not be included in the calculation for 3rd column's numerical values. What I mean is shown below:

Code:
c<B>r<10>a<2351>R<ALA>A<N>	c<B>r<10>a<2352>R<ALA>A<CA>	8.23332	1.44755	.	.
c<B>r<10>a<2351>R<ALA>A<N>	c<B>r<10>a<2353>R<ALA>A<C>	0.297706	2.44449	.	.
c<B>r<10>a<2351>R<ALA>A<N>	c<B>r<10>a<2355>R<ALA>A<CB>	2.09341	2.40713	.	.
c<B>r<10>a<2351>R<ALA>A<N>	c<B>r<11>a<2356>R<LEU>A<N>	0.907353	2.84241	.	.
c<B>r<10>a<2351>R<ALA>A<N>	c<solvent>	1.01406	5.75	.	.
c<B>r<10>a<2352>R<ALA>A<CA>	c<B>r<10>a<2353>R<ALA>A<C>	6.44947	1.52475	.	.
c<B>r<10>a<2352>R<ALA>A<CA>	c<B>r<10>a<2354>R<ALA>A<O>	3.8033	2.38154	.	.
c<B>r<10>a<2352>R<ALA>A<CA>	c<B>r<10>a<2355>R<ALA>A<CB>	13.1908	1.50033	.	.
c<B>r<10>a<2352>R<ALA>A<CA>	c<B>r<11>a<2356>R<LEU>A<N>	0.256203	2.48739	.	.
c<B>r<10>a<2352>R<ALA>A<CA>	c<B>r<13>a<2373>R<ASP>A<CB>	3.90918	4.34633	.	.

How could this be achieved by my script written above through awk?
# 26  
Old 06-13-2019
/.../ in awk is a regex constant, so it tries to match two uppercase "A" (AA)in your above case. Drop the slashes to match the contents of variable AA.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Unexpected result from awk

Hello, Giving those commands: cat > myfile 1 2 3 ^D cat myfile | awk '{ s=s+$1 ; print s}' The output is: 1 3 6 It seems like this command iterates each time on a different row so $1 is the first field of each row.. But what caused it to refer to each row ?. What I mean... (3 Replies)
Discussion started by: uniran
3 Replies

2. UNIX for Beginners Questions & Answers

Line duplication with awk?!

So while this seemed totally trivial it turned out to be much more difficult than I had thought. I have a file with 3 rows, and I "just" want to add each field n number of times. E.g. > cat file.txt 0.5 -0.1 0.6 for n=3 into: cat newfile.txt 0.5 0.5 0.5 -0.1 -0.1 -0.1 0.6 0.6 0.6 I... (4 Replies)
Discussion started by: Glorp
4 Replies

3. Linux

De-Duplication Problem

Hi all, I download and install lessfs for deduplication, I copy files in /SharedFiles directory and lessfs work right and not store again copy files, but, when i delete all files in /SharedFiles , not return free space to total space, files not show in /SharedFiles , but not copy new files in... (3 Replies)
Discussion started by: saeedha
3 Replies

4. Programming

Table Duplication in PHP

Hey, I am making a Facebook like Page system as my first project, So far it's been bate in mind I did it from my 3DS at the same time as my PC gets replaced, So far it's turned out great. Now I am on to creation the blocking system I need to get the code to say If the user already likes the... (0 Replies)
Discussion started by: AimyThomas
0 Replies

5. UNIX for Advanced & Expert Users

File Descriptor redirection and duplication

i have many questions concerning the FD. it was stated that "to redirect Error to output std, you have to write the following code" # ls -alt FileNotThere File > logfile 2>&1 # cat logfile ls: cannot access FileNotThere: No such file or directory -rw-r--r-- 1 root root 0 2010-02-26... (9 Replies)
Discussion started by: ahmad.zuhd
9 Replies

6. Shell Programming and Scripting

How to avoid duplication within 2 files?

Hi all, Actually 2 files are there - file1, file2. file1 contains ---> london mosco america russia mosco file2 contains --> europe india japan mosco england london Question is I want to print all the city names without duplication cities in those... (10 Replies)
Discussion started by: balan_mca
10 Replies

7. Shell Programming and Scripting

File Duplication Script?

I have a file, let's say 1.jpg, and I have a text file that contains a list of filenames I would like to duplicate 1.jpg as (i.e., 2.jpg, 3.jpg, 4.jpg, etc.). The filenames that I want to create are all on separate lines, one per line. I'm sure there's a simple solution, but I'm not claiming to... (7 Replies)
Discussion started by: futurestar
7 Replies

8. UNIX for Advanced & Expert Users

mount LVM duplication drives

Hi, I'm stuck in an awkward situation please help :) I have two identical Seagate 80GB harddrives. My objective is a bit strange. 1.I want to have a cloned disk as bootable backup 2.When booting using the master drive, I also want to mount the cloned backup disk so I can do incremental... (6 Replies)
Discussion started by: onthetopo
6 Replies

9. HP-UX

awk to output cmd result

I was wondering if it was possible to tell awk to print the output of a command in the print. .... | awk '{print $0}' I would like it to print the date right before $0, so something like (this doesn't work though) .... | awk '{print date $0}' (4 Replies)
Discussion started by: IMTheNachoMan
4 Replies

10. Windows & DOS: Issues & Discussions

File Duplication

hi all how to find the file duplication in a windows 2000 server as usual replies are sincerely appreciated. thanks raguram R (3 Replies)
Discussion started by: raguramtgr
3 Replies
Login or Register to Ask a Question