filter lscpu output and print to single line [closed] - regex

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 12 days ago.
Improve this question
I want to print the CPU's name, followed by the MHz (min, current and max, in that order).
The best I could get so far is 4 lines of output in their original order (name, current MHz, max MHz, min MHz):
Code tried
lscpu | sed -n -e "s/Model name: *//p" -e "s/CPU min MHz: *//p" -e "s/CPU MHz: *//p" -e "s/CPU max MHz: *//p"
Output
AMD EPYC 7443 24-Core Processor
1786.548
4035.6440
1500.0000
Expected Output
AMD EPYC 7443 24-Core Processor # 1500.0000 < 1786.548 < 4035.6440 MHz

Just literally read the lines and output what you want to output.
.... | { read first; read second; read third; read fourth; echo "$first # $fourth < $second < $third MHz"; }

Related

Difference between 'bc' and 'bc -l' in Bash when I try to find modulus of a number [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
The community reviewed whether to reopen this question 2 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
Why does Unix give the result 0 when I execute the following command?
echo "7%2" | bc -l
And give result 1 when I execute the following command?
echo "7%2" | bc
why does Unix gives result 0 when I execute the command: echo "7%2" | bc -l
From the bc manual:
If bc is invoked with the -l option, a math library is preloaded and the default scale is set to 20.
And
expr % expr
The result of the expression is the "remainder" and it
is computed in the following way. To compute a%b,
first a/b is
computed to scale digits. That result is used to compute a-(a/b)*b
to the scale of the maximum of scale+scale(b) and scale(a). If
scale is set to zero and both expressions are integers this
expression is the integer remainder function.
So:
a=7 b=2
a/b = 7 / 2 = 3.50000000000000000000000000000000000000000000000000
7%2 = a-(a/b)*b =
= 7 - (7/2)*2 =
= 7 - (3.50000000000000000000000000000000000000000000000000) * 2 =
= 7 - 7 =
= 0
and gives result 1 when I execute the command: echo "7%2" | bc
From the bc manual:
scale defines how some operations use digits after the decimal point. The default value of scale is 0.
In that case:
a=7 b=2
a/b = 7 / 2 = 3 # scale is 0, rounds down
a%b = a-(a/b)*b =
= 7 - (7/2)*2 =
= 7 - 3 * 2 =
= 7 - 6 =
= 1
Because the 7/2 is computed with different scale, the resulting expression differs.

CLI method for vlookup like search [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have a huge csv file, demo.csv (few GBs in size) which has 3 columns like the following:
$ cat demo.csv
call_start_time,called_no,calling_no
43284.85326,1111111111,2222222222
43284.83192,3333333333,1111111111
43284.83205,2222222222,1111111111
43284.81304,4444444444,3333333333
I am trying to find the rows which has repeated values in either column 2 or 3 (whatever the order). For example, this should be the output for the data shown above:
call_start_time,called_no,calling_no
43284.85326,1111111111,2222222222
43284.83205,2222222222,1111111111
I tried to use csvkit:
csvsql --query "select called_no, calling_no, call_start_time, count(1) from file123 group by called_no,calling_no having count(1)>1" file123.csv > new.csv
With awk you can build an associative array a with records as values and keys k build with the fields $2 and $3 sorted and joined with a pipe.
awk -F, 'NR==1; { k=($3<$2) ? $3"|"$2 : $2"|"$3; if (a[k]) { if (a[k]!="#") {print a[k];a[k]="#"} print} else a[k]=$0}' file
If the current record has a key that already exists, the stored record is printed (only if it is the first time) and the current record is printed too.
$ awk '
NR==1 { print; next }
{ key = ($2>$3 ? $2 FS $3 : $3 FS $2) }
seen[key]++ { print orig[key] $0; delete orig[key]; next }
{ orig[key] = $0 ORS }
' file
call_start_time called_no calling_no
43284.85326 1111111111 2222222222
43284.83205 2222222222 1111111111

parsing time command in perl [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
When i issue the command /usr/bin/time script.sh it can vary in time because of the load of course (sometimes could be 10 secs and sometime could be 2 minutes), problem is that i need notification if time execution is higher than 30 sec (could also include minutes..) and warning if is 20-30 seconds.
What is the best way to catch all time values for requested tresholds:
/usr/bin/time ./script.sh | awk'/real/ {print $2}'
30.0
/usr/bin/time ./script.sh | awk'/real/ {print $2}'
1:24.2
/usr/bin/time ./script.sh | awk'/real/ {print $2}'
3.1
Given the following warning thresholds:
Critical: 30 seconds or longer
Warning: 20 seconds to 30 seconds
OK: less than 20 seconds
And based on the output of /usr/bin/time on your machine, which seems to use a format of hh:mm:ss.d with optional hours and minutes places:
my $time = `/usr/bin/time ./vladtest.sh | awk '/real/ {print $2}'`
my $status;
if ($time =~ /^[01]?\d\./) { # time is 0-9 seconds or 10-19 seconds
$status = "OK";
}
elsif ($time =~ /^(2\d|30)\./) { # time is 20-30 seconds
$status = "WARNING";
}
else { # any other time is critical
$status = "CRITICAL";
}

Regex wheel size or digits after point [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
These are 2 samples:
Size: 15x6.5
Size: 15x7
I need a regex command to capture the digits before "x" and another regex command to capture digits after.
I want to obtain something like this:
Size: 15x6.5 --> 1) 15 2) 6.5
Size: 15x7 --> 1) 15 2) 7
Use regular expression: (\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)
You didn't specified the regular expression engine you are using.
Python
>>> import re
>>> matched = re.search(r'(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)', 'Size: 15x6.5')
>>> matched.groups()
('15', '6.5')
>>> matched = re.search(r'(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)', 'Size: 15x7')
>>> matched.groups()
('15', '7')
Ruby
>> 'Size: 15x6.5'.scan(/(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)/)
=> [["15", "6.5"]]
>> 'Size: 15x7'.scan(/(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)/)
=> [["15", "7"]]
Javascript
> 'Size: 15x6.5'.match(/(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)/)
["15x6.5", "15", "6.5"]
> 'Size: 15x7'.match(/(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)/)
["15x7", "15", "7"]
UPDATE
Use (\d+(?:\.\d+)?)(?=x) and (?<=x)(\d+(?:\.\d+)?)

bash script to remove prefix in file name [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
A bash script request(or fish script).
I have a bunch of files like:
SDF1211B-03 - name - lastname.info
SDF1213B-04 - names - lastnames.info
SDF1211B-05 - name & name - lastname & lastname.info
but I want to change all of them to:
name - lastname.info
names - lastnames.info
name & name - lastname & lastname.info
I would do this with a for loop and the ${X#Y} shell pattern:
for f in SDF?????-??' - '* ; do
mv "$f" "${f#SDF?????-?? - }"
done
You could do this:
for x in SDF*.info; do
mv "$x" "$(echo $x | cut -c14-)"
done