Extract and place in variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract and place in variable
# 1  
Old 08-30-2009
Extract and place in variable

If i wanted to extract the number of collisions from the eth0 section of the ifconfig file and have the output placed in a variable how would i do this?
I can get the output displayed using:

/sbin/ifconfig eth0 | grep "collisions"

What command would i now use to place the output in a variable known as "Collisions"?
# 2  
Old 08-30-2009
The followmnmg will do what you are after:
Code:
COLLISIONCOUNT=`/sbin/ifconfig eth0 | grep "collisions"`
COLLMAX=99
if [ ${COLLISIONCOUNT} -gt ${COLLMAX} ] then
  echo "Collision count is greater than ${COLLMAX}!"
else
  echo "Collision count is less than than `expr ${COLLMAX}+1`!"
fi

It is the ` characters that run what is inside them and cause the output to be passed to the variable before the equals sign.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to extract value from a variable

Hello All, I have a variable named as output which holds value as below - output= trailer NULL data NULL] I need to extract bdfo_run_date value which is '41991' out of this, any pointers will be greatly appreciated. (4 Replies)
Discussion started by: ektubbe
4 Replies

2. Shell Programming and Scripting

How to merge variable data from another file into specific place?

Hello, I'm trying to create multiple commands using a variable input from another file but am not getting any successful results. Basically, file1.txt contains multiple lines with single words: <file1.txt> yellow blue black white I want to create multiple echo commands with these... (8 Replies)
Discussion started by: demmel
8 Replies

3. UNIX for Advanced & Expert Users

Place the results of a CUT command into a variable

I am being passed a file in UNIX, ie: variable.txt I need to extract the first part of the file content, up to the period, content ie: common_dir.second_output cut -d'.' -f1 /content/stores/variable.txt I then need to utilize the results to create a variable ($1), and test on that... (4 Replies)
Discussion started by: talonbow
4 Replies

4. Shell Programming and Scripting

Use GREP to count number of records and place it in a variable

I am trying to count the number of records from different files using grep, and then place the result in a separate variable for each file, so at the end of my shell script, I can sum all the variables and check if the number of records are equal to what I was expecting. It is weird butwc -ldoes... (2 Replies)
Discussion started by: dhruuv369
2 Replies

5. UNIX for Dummies Questions & Answers

Extract variable name in a string

Hi, I'm doing a script to list all scripts called by a "master" script. But I have an issue as there is some variables in the name of the called scripts. Example: % cat master_script.sh ENVIR=PROD VERSION=1.2 /users/maturix/$ENVIR/program_$VERSION.shI would like my script displays a kind... (7 Replies)
Discussion started by: maturix
7 Replies

6. Shell Programming and Scripting

Extract attachment from mail and place it in a directory

Hi, I have a requiremnent that i have to read a mail from a mail box and extract the attachment from that mail and place it in a directory. First of all is it possible in unix ? if so could you please help me out how it can be done Thanks in advance. (3 Replies)
Discussion started by: krishna_gnv
3 Replies

7. Solaris

What is the best way to copy data from place to another place?

Dear Gurus, I need you to advice or suggestion about the best solution to copy data around 200-300G from serverA(location A) to serverB(location B). Normally, I will share folder and then copy but it takes too long time(about 2 days). Do you have any suggestion or which way should be... (9 Replies)
Discussion started by: unitipon
9 Replies

8. Shell Programming and Scripting

display changing variable in one place on screen in ksh

Is it possible using just korn shell script to display a variable on the screen that is constantly changing in on place on the screen, to tell it in coordinates or something? In a loop, echo will print a new line each time, can I make it a static position? Thanks (7 Replies)
Discussion started by: raidzero
7 Replies

9. UNIX for Dummies Questions & Answers

extract characters from a variable

Hi All, I have scenario as below, I want to cut the characters and store it variable2.. and want to display the variable2.. as shown below... eg: the size may differs , i am show just an example..... numbers are not fixed in variable1..i want to extract characters and... (1 Reply)
Discussion started by: G.K.K
1 Replies

10. Shell Programming and Scripting

extract x lines after a pattern - place each result in separate file

Hi all, I have many files that have 1 or more occurrences of the information I want. There are two distinct sets of information. I want get this info and place each occurrence in its own file. The 3 lines before one set are this grid 00 01 02 16 17 18 **40 lines of code I want to... (5 Replies)
Discussion started by: gobi
5 Replies
Login or Register to Ask a Question