Sponsored Content
Top Forums Shell Programming and Scripting Search file for string and store last result to variable Post 302491624 by Chubler_XL on Thursday 27th of January 2011 11:27:06 PM
Old 01-28-2011
Code:
var1=$(grep "energy(sigma->0)=" text.file)
var2=${var1##*= }

This User Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to store query multiple result in shell script variable(Array)

:) Suppose,I have one table A. Table A have one column. Table A have 10 rows. I want this 10 rows store into shell script variable. like #!/bin/ksh v_shell_var=Hi here in call oracle , through loop How can I store table A's 10 rows into v_shell_var (Shell Script Array). Regards, Div (4 Replies)
Discussion started by: div_Neev
4 Replies

2. Shell Programming and Scripting

Prase a file and store and result to an array

Dear all, I have a file having the following formats: ThreadFail=Web1=1234 ThreadFail=Web2=2345 ThreadFail=Web3=12 ConnectionFail=DB1=11 ConnectionFail=DB2=22 The number of lines will be different from every time . How can I parse the file and store the result to an a array inside... (6 Replies)
Discussion started by: youareapkman
6 Replies

3. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

4. Shell Programming and Scripting

How to search for string and return binary result?

Hi, I have a problem that I am sure someone will know the answer to. Currently I have a script which returns a binary output if it finds a certain search string (in this case relating to a DRBD cluster) as follows: searchstring="cs:Connected st:Primary/Secondary ds:UpToDate/UpToDate" && echo... (3 Replies)
Discussion started by: almightybunghol
3 Replies

5. Programming

how to store string in variable

sorry i'm newbies c programer how to store string to variable with value flexible. example int hh=1; ---> value flexible 1,2,3,4,5; int xx=1; ---> value flexible 1,2,3,4,5; char test="value=%d and value=%d",hh,xx; --> not working char test2="value2=%d and value2=%d",hh,xx; --> not... (1 Reply)
Discussion started by: slackman
1 Replies

6. Shell Programming and Scripting

How to store result of grep into a variable?

In a directory i have a file *output* whose contents are changing for every simulation. zgrep "trace file is" *output* | zgrep g o/p: trace file is Int_01.1352176388z4f56ec33.0.trace.gz I want to extract "Int_01.1352176388z4f56ec33.0.trace.gz" from the above result into a variable. i... (2 Replies)
Discussion started by: twistedpair
2 Replies

7. Shell Programming and Scripting

Extract a string from a file and store it in variable

Hi, I've a file ImageSizeDetails.txt with the following contents: Image Name: swncd 01.10.00.04 Created: Wed Jan 9 14:05:48 2013 Image Type: ARM Linux Multi-File Image (gzip compressed) Data Size: 7351011 Bytes = 7178.72 kB = 7.01 MB Load Address: 00008000 Entry Point: ... (6 Replies)
Discussion started by: Parameswaran
6 Replies

8. Shell Programming and Scripting

Store result variable

Friends have the following problem: cat $PATH_DAT/mr.txt | nawk 'BEGIN { CantPnt=0; NumReg=0; FS="|" } { NumReg++ CantPnt=CantPnt+int($2) } END{ printf... (5 Replies)
Discussion started by: tricampeon81
5 Replies

9. Shell Programming and Scripting

Bash to store result in variable for other lines in script to use

I can not figure out how to capture the $filename variable store by the bash. #!/bin/bash # oldest folder stored as variable for analysis, version log created, and quality indicators matched to run dir=/home/cmccabe/Desktop/NGS/test find "$dir" -maxdepth 1 -mindepth 1 -type d -printf... (5 Replies)
Discussion started by: cmccabe
5 Replies

10. UNIX for Beginners Questions & Answers

Need help with how to search a file for a variable string and delete that line

Hi, I have a working script. It does what I am intending it to but a bit confused whether the sed part is supposed to be working or not. Further down is the script with the sed part that should have been working but not and the grep -v part which is the workaround that I am using at the... (10 Replies)
Discussion started by: newbie_01
10 Replies
grep(1) 						      General Commands Manual							   grep(1)

NAME
grep, egrep, fgrep - search a file for a pattern SYNOPSIS
Plain call with pattern pattern [file ...] Call with (multiple) -e pattern pattern] ... [file ...] Call with -f file pattern_file] [file ...] Obsolescent: [expression] [file ...] [strings] [file ...] DESCRIPTION
The command searches the input text files (standard input default) for lines matching a pattern. Normally, each line found is copied to the standard output. supports the Basic Regular Expression syntax (see regexp(5)). The option supports Extended Regular Expression (ERE) syntax (see regexp(5)). The option searches for fixed strings using the fast Boyer-Moore string searching algorithm. The and options treat newlines embedded in the pattern as alternation characters. A null expression or string matches every line. The forms and are maintained for backward compatibility. The use of the and options is recommended for portability. Options Extended regular expressions. Each pattern specified is a sequence of one or more EREs. The EREs can be separated by newline characters or given in separate expression options. A pattern matches an input line if any ERE in the sequence matches the contents of the input line without its trailing newline character. The same functionality is obtained by using Fixed strings. Each pattern specified is a sequence of one or more strings. Strings can be separated by newline characters or given in separate expression options. A pattern matches an input line if the line contains any of the strings in the sequence. The same functionality is obtained by using Each line is preceded by the block number on which it was found. This is useful in locating disk block numbers by context. Block numbers are calculated by dividing by 512 the number of bytes that have been read from the file and rounding down the result. Only a count of matching lines is printed. Same as a simple expression argument, but useful when the expression begins with a hyphen Multiple options can be used to specify multiple patterns; an input line is selected if it matches any of the specified patterns. The regular expression and or strings list is taken from the pattern_file. Suppress printing of filenames when searching multiple files. Ignore uppercase/lowercase distinctions during comparisons. Only the names of files with matching lines are listed (once), separated by newlines. If standard input is searched, a path name of will be written, in the POSIX locale. In other locales, may be replaced by something more appropriate in those locales. Each line is preceded by its relative line number in the file starting at 1. The line number is reset for each file searched. This option is ignored if or is specified. (Quiet) Do not write anything to the standard output, regardless of matching lines. Exit with zero status upon finding the first matching line. Overrides any options that would produce output. Error messages produced for nonexistent or unreadable files are suppressed. All lines but those matching are printed. Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or pre- ceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore. (eXact) Matches are recognized only when the entire input line matches the fixed string or regular expression. The file name is output in all the cases in which output is generated if there are more than one input file, unless the -h option is speci- fied. Care should be taken when using the characters and in expression, because they are also meaningful to the shell. It is safest to enclose the entire expression argument in single quotes EXTERNAL INFLUENCES
Environment Variables determines the locale to use for the locale categories when both and the corresponding environment variable (beginning with do not specify a locale. If is not specified or is set to the empty string, a default of (see lang(5)) is used. determines the locale to use to override any values for locale categories specified by the settings of or any environment variables begin- ning with determines the collating sequence used in evaluating regular expressions. determines the interpretation of text as single byte and/or multi-byte characters, the classification of characters as letters, the case information for the option, and the characters matched by character class expressions in regular expressions. determines the language in which messages are displayed. If any internationalization variable contains an invalid setting, the commands behave as if all internationalization variables are set to See environ(5). International Code Set Support Single-byte and multi-byte character code sets are supported. RETURN VALUE
Upon completion, returns one of the following values: One or more matches found. No match found. Syntax error or inaccessible file (even if matches were found). EXAMPLES
In the POSIX shell (sh(1)) the following example searches two files, finding all lines containing occurrences of any of four strings: Note that the single quotes are necessary to tell when the strings have ended and the file names have begun. For the C shell (see csh(1)) the following command can be used: To search a file named containing the following entries: the command: prints: To search a file for lines that contain either a or use either of the following commands: Search all files in the current directory for the string Search all files in the current directory subtree for the string and ensure that no error occurs due to file name expansion exceeding sys- tem argument list limits: The previous example does not print the name of files where string appears. To force to print file names, add a second argument to the command portion of the command line: In this form, the first file name is that produced by and the second file name is the null file. WARNINGS
(XPG4 only.) If the option is specified, the exit status will be zero if an input line is selected, even if an error was detected. Other- wise, default actions will be performed. If the option is specified with non-word constituent characters, then the output is unexpected. SEE ALSO
sed(1), sh(1), regcomp(3C), environ(5), lang(5), regexp(5). STANDARDS CONFORMANCE
grep(1)
All times are GMT -4. The time now is 05:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy