Sponsored Content
Top Forums UNIX for Dummies Questions & Answers putting grep -c results number in a variable Post 302284114 by pmm on Wednesday 4th of February 2009 09:30:12 PM
Old 02-04-2009
Code:
read name

results=`grep -c $name file`
if [ $results == 0 ];
then echo "No results found."
else
echo "found $results results"
fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep results to store in a shell variable

I have the results of a grep with -n store in a shell variable ie VAR=`grep -n -e 'PATTERN' file` How ever I am missing the line breaks in the variable , How do I store the resualts of grep with many lines in to a variables. I want the varable should be the sawmway as we do the grep grep... (3 Replies)
Discussion started by: jojan
3 Replies

2. UNIX for Dummies Questions & Answers

number of occurence using grep -c then assigning it to a variable

Hi guys! I need to count the occurence of a certain pattern. For example the pattern is PC. the contents of the file sample.txt: A PC asdfgadfjkl asdfa PC sadfaf fdsPCasdfg if i use grep -c PC sample.txt it will display 3 as the number of occurence how do i save that number to a... (1 Reply)
Discussion started by: khestoi
1 Replies

3. UNIX for Dummies Questions & Answers

Using GREP/AWK to extract a number and store it as a variable

Hello, I have a question regarding the awk command. Here is the line I need to grep: 1 F= -.13250138E+03 E0= -.13249556E+03 d E =-.174650E-01 mag= 35.2157 Instead of displaying the number in red I would like to store it as a variable such as X. Is there a way to do this? Thanks for any... (3 Replies)
Discussion started by: modey3
3 Replies

4. Shell Programming and Scripting

Putting new line after certain number of character

Hi, I want, if a line is more than 80 characters length then put a new line with 4 space after each 80 characters to indent the data at same position. Input: 200 Geoid and gravity anomaly data of conjugate regions of Bay of Bengal and Enderby Basin: New constraints on breakup and early... (3 Replies)
Discussion started by: srsahu75
3 Replies

5. Shell Programming and Scripting

Adding grep'd results in a variable

Here is one I am baffled with; I have not used unix for a while and now that I am back it has been fun remembering and I have enjoyed it, for the most past. this is in ksh. I need to search in a file for the line with X1 and cut columns 20-25, put them into a variable, added them (dollar... (3 Replies)
Discussion started by: CougarMutt
3 Replies

6. Shell Programming and Scripting

Help awk/sed: putting a space after numbers:to separate number and characters.

Hi Experts, How to sepearate the list digit with letters : with a space from where the letters begins, or other words from where the digits ended. file 52087mo(enbatl) 52049mo(enbatl) 52085mo(enbatl) 25051mo(enbatl) The output should be looks like: 52087 mo(enbatl) 52049... (10 Replies)
Discussion started by: rveri
10 Replies

7. Shell Programming and Scripting

Putting mysql column value in variable

Hello, i have the following code : somevariable=`mysql -u root --password="" databasename -e "select count(column_name) from table_name where id=1 and id_age=2 ; " --skip-column-names -s -N` if ] then .... It gives the message ")syntax error: invalid arithmetic operator (error... (2 Replies)
Discussion started by: juve11
2 Replies

8. 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

9. Shell Programming and Scripting

I want to add a variable for the results from the formula of one variable and results of another var

Good morning all, This is the file name in question OD_Orders_2019-02-19.csv I am trying to create a bash script to read into files with yesterdays date on the file name while retaining the rest of the files name. I would like for $y to equal, the name of the file with a formula output with... (2 Replies)
Discussion started by: Ibrahim A
2 Replies

10. UNIX for Beginners Questions & Answers

Grep command to show the number of results

Hi I wanted to know if there is an option in grep command to show the number of results (not the number of lines of findings). Thanks (14 Replies)
Discussion started by: abdossamad2003
14 Replies
SQLSRV_NEXT_RESULT(3)													     SQLSRV_NEXT_RESULT(3)

sqlsrv_next_result - Makes the next result of the specified statement active

SYNOPSIS
mixed sqlsrv_next_result (resource $stmt) DESCRIPTION
Makes the next result of the specified statement active. Results include result sets, row counts, and output parameters. PARAMETERS
o $stmt - The statment on which the next result is being called. RETURN VALUES
Returns TRUE if the next result was successfully retrieved, FALSE if an error occurred, and NULL if there are no more results to retrieve. EXAMPLES
Example #1 sqlsrv_next_result(3) example The following example executes a batch query that inserts into a table and then selects from the table. This produces two results on the statement: one for the rows affected by the INSERT and one for the rows returned by the SELECT. To get to the rows returned by the SELECT, sqlsrv_next_result(3) must be called to move past the first result. <?php $serverName = "serverNamesqlexpress"; $connectionInfo = array("Database"=>"dbName", "UID"=>"userName", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo); $query = "INSERT INTO Table_1 (id, data) VALUES (?,?); SELECT * FROM TABLE_1;"; $params = array(1, "some data"); $stmt = sqlsrv_query($conn, $query, $params); // Consume the first result (rows affected by INSERT) without calling sqlsrv_next_result. echo "Rows affected: ".sqlsrv_rows_affected($stmt)."<br />"; // Move to the next result and display results. $next_result = sqlsrv_next_result($stmt); if( $next_result ) { while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)){ echo $row['id'].": ".$row['data']."<br />"; } } elseif( is_null($next_result)) { echo "No more results.<br />"; } else { die(print_r(sqlsrv_errors(), true)); } ?> SEE ALSO
sqlsrv_query(3), sqlsrv_fetch_array(3), sqlsrv_rows_affected(3). PHP Documentation Group SQLSRV_NEXT_RESULT(3)
All times are GMT -4. The time now is 08:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy