mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Linux

Reply
 
Thread Tools
Old 2022-07-24, 23:48   #1
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

1,607 Posts
Default Percentage of two files

Under Linux, in same directory I have two files, One is file a. txt and second is b.txt
So I need script that will read number of lines in a.txt and divide it with number of lines in b.txt and *100 to get percentage.
pepi37 is online now   Reply With Quote
Old 2022-07-25, 03:21   #2
mathwiz
 
Mar 2019

1001101102 Posts
Default

How about something like:

Code:
$ echo 100*`wc -l a.txt | awk '{print $1}'`/`wc -l b.txt | awk '{print $1}'` | bc -l
mathwiz is offline   Reply With Quote
Old 2022-07-25, 06:14   #3
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

1,607 Posts
Default

Quote:
Originally Posted by mathwiz View Post
How about something like:

Code:
$ echo 100*`wc -l a.txt | awk '{print $1}'`/`wc -l b.txt | awk '{print $1}'` | bc -l
It looks like not working
Quote:
p: 1: $: not found
pepi37 is online now   Reply With Quote
Old 2022-07-25, 10:07   #4
Batalov
 
Batalov's Avatar
 
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2

2·33·5·37 Posts
Default

echo `wc -l a` `wc -l b` |awk '{print $1*100/$3 "%"}'
Batalov is offline   Reply With Quote
Old 2022-07-25, 21:40   #5
kruoli
 
kruoli's Avatar
 
"Oliver"
Sep 2017
Porta Westfalica, DE

24·7·11 Posts
Default

Quote:
Originally Posted by pepi37 View Post
It looks like not working
You need to omit the very first dollar sign.
kruoli is online now   Reply With Quote
Old 2022-07-25, 22:10   #6
retina
Undefined
 
retina's Avatar
 
"The unspeakable one"
Jun 2006
My evil lair

29·229 Posts
Default

Quote:
Originally Posted by kruoli View Post
You need to omit the very first dollar sign.
You can also omit the final   -l.
retina is offline   Reply With Quote
Old 2022-07-25, 23:27   #7
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

1,607 Posts
Default

Quote:
Originally Posted by Batalov View Post
echo `wc -l a` `wc -l b` |awk '{print $1*100/$3 "%"}'
As always , bingo! :)
Thanks
But I wrote the question a little clumsily :( ( my miastake)

File a has always same content (only number is changed) (example)

Quote:
a.txt 193
so that is content of file a

I need some way to extract only number from file a in this case 193 and divide it with second value. I try with grep, but grep remove line, and since it is all in one line and that will not be changed ,grep is no use for me :(
Any suggestions?
pepi37 is online now   Reply With Quote
Old 2022-07-25, 23:35   #8
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

1,607 Posts
Default

Quote:
Originally Posted by mathwiz View Post
How about something like:

Code:
$ echo 100*`wc -l a.txt | awk '{print $1}'`/`wc -l b.txt | awk '{print $1}'` | bc -l

Code:
echo 100* `wc -l a.txt | awk '{print $1}'`/`wc -l b.txt | awk '{print $1}'` | bc

without -l result is rounded
pepi37 is online now   Reply With Quote
Old 2022-07-25, 23:42   #9
mathwiz
 
Mar 2019

2·5·31 Posts
Default

Quote:
Originally Posted by pepi37 View Post
Code:
echo 100* `wc -l a.txt | awk '{print $1}'`/`wc -l b.txt | awk '{print $1}'` | bc

without -l result is rounded
You should learn tools like wc, grep, awk etc and understand what they are doing and how to chain them together.
mathwiz is offline   Reply With Quote
Old 2022-07-25, 23:47   #10
pepi37
 
pepi37's Avatar
 
Dec 2011
After milion nines:)

1,607 Posts
Default

Quote:
Originally Posted by mathwiz View Post
You should learn tools like wc, grep, awk etc and understand what they are doing and how to chain them together.

Dont think that I just have some idea and post my question here without any try before. Linux is new OS to me,so I learn when I have time. Maybe my question are silly to you, but we all start at some point.
pepi37 is online now   Reply With Quote
Old 2022-07-26, 00:51   #11
retina
Undefined
 
retina's Avatar
 
"The unspeakable one"
Jun 2006
My evil lair

147618 Posts
Default

man echo
man awk
man bc
man grep
man wc
...

My favourite is man date
retina is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
What percentage of users and/or total GHz days are being used for TF, P-1, DC, PRP, etc.? piforbreakfast PrimeNet 10 2022-06-13 02:51
Mechanics of DC instead of LL percentage Fred PrimeNet 1 2016-02-29 02:19
Fines based on a percentage of net worth jasong jasong 30 2013-06-06 07:20
Bug in P-1 completion percentage report NBtarheel_33 Software 3 2010-05-21 16:47
Modifying Percentage-Done Display? Primeinator Software 4 2005-03-15 05:32

All times are UTC. The time now is 10:49.


Tue Dec 6 10:49:30 UTC 2022 up 110 days, 8:18, 0 users, load averages: 1.23, 0.89, 0.86

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.

≠ ± ∓ ÷ × · − √ ‰ ⊗ ⊕ ⊖ ⊘ ⊙ ≤ ≥ ≦ ≧ ≨ ≩ ≺ ≻ ≼ ≽ ⊏ ⊐ ⊑ ⊒ ² ³ °
∠ ∟ ° ≅ ~ ‖ ⟂ ⫛
≡ ≜ ≈ ∝ ∞ ≪ ≫ ⌊⌋ ⌈⌉ ∘ ∏ ∐ ∑ ∧ ∨ ∩ ∪ ⨀ ⊕ ⊗ 𝖕 𝖖 𝖗 ⊲ ⊳
∅ ∖ ∁ ↦ ↣ ∩ ∪ ⊆ ⊂ ⊄ ⊊ ⊇ ⊃ ⊅ ⊋ ⊖ ∈ ∉ ∋ ∌ ℕ ℤ ℚ ℝ ℂ ℵ ℶ ℷ ℸ 𝓟
¬ ∨ ∧ ⊕ → ← ⇒ ⇐ ⇔ ∀ ∃ ∄ ∴ ∵ ⊤ ⊥ ⊢ ⊨ ⫤ ⊣ … ⋯ ⋮ ⋰ ⋱
∫ ∬ ∭ ∮ ∯ ∰ ∇ ∆ δ ∂ ℱ ℒ ℓ
𝛢𝛼 𝛣𝛽 𝛤𝛾 𝛥𝛿 𝛦𝜀𝜖 𝛧𝜁 𝛨𝜂 𝛩𝜃𝜗 𝛪𝜄 𝛫𝜅 𝛬𝜆 𝛭𝜇 𝛮𝜈 𝛯𝜉 𝛰𝜊 𝛱𝜋 𝛲𝜌 𝛴𝜎𝜍 𝛵𝜏 𝛶𝜐 𝛷𝜙𝜑 𝛸𝜒 𝛹𝜓 𝛺𝜔