0

How do I convert my output vendor_id : GenuineIntel to vendor_id = GenuineIntel using the cut command?

#!/bin/bash

VENDORID=`cat /proc/cpuinfo | grep 'vendor_id'|cut -d`=`-f 5`
vendor_id: GenuineIntel
echo $VENDORID
1
  • Avoid backquotes (used for sub-commands), do not use them as single quotes. Commented Jun 1, 2016 at 22:03

3 Answers 3

1

You can use translate:

vendorid=$(grep 'vender_id' /proc/cpuinfo | tr ':' '=')
printf "%s\n" "$vendorid"

I changed backticks to $(..) since they are easier to nest. Also remember to double quote your variable expansions $vendorid -> "$vendorid" or it will undergo word splitting.

tr will in this case change all colons to equal signs, eg:

% echo "a:b:c" | tr ':' '='
a=b=c
Sign up to request clarification or add additional context in comments.

3 Comments

@user3613649 I'm happy I could help :-)
I also want to run a script for the utility from my CPU
@user3613649 Hopefully now you know how to progress? :-)
1
VENDORID=$(sed -n '/vendor_id/{s/:/=/p;q}' /proc/cpuinfo)

1 Comment

This is a good answer, care you elaborate what {s/:/=/p;q} does - might not be obvious?
0

Translate the character :into = with

 tr ':' '=' < /proc/cpuinfo

Assign to a variable with

vendorid=$(tr ':' '=' < /proc/cpuinfo)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.