Sponsored Content
Top Forums Shell Programming and Scripting command to grep the variable from file Post 302575871 by dbashyam on Wednesday 23rd of November 2011 05:19:06 AM
Old 11-23-2011
command to grep the variable from file

Hi,

I am looking for the following:

1. A command to 'grep' the variable from a file
2. And check whether the entered variable is empty in that file

I have a file as given below:

IAGLOBAL_USERID=admin

I want to check with a whether the variable contains a value, say here its admin if it contains value I will proceed ahead else I should give three tries for the user if in those three tries if the user does not enter the userid then I will exit.

I did the following:

Code:
var1=`cat $NCO/response_uid.txt | grep -i IAGLOBAL_WASUserID | cut -d'=' -f1`
var2=$(echo "${var1}" | sed -e 's/^ *//g;s/ *$//g')
echo $var2
if [ -z "$var2" ];
then
rm -rf $NCO/response_uid.txt
rm -rf $NCO/response_def.txt
exit 1;
fi

Any ideas?

Thanks,
Dinesh
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep from a file variable

I am wanting to test the output from a script. If the out put = Object does not exist. I need to delete the output file. I am using , filecontents=`grep -i Object does not exist. $1.txt` then I test the variable with, if ; then delete file But I get an error, grep: can't open... (5 Replies)
Discussion started by: jagannatha
5 Replies

2. Shell Programming and Scripting

assign subst|grep|sed command result to a variable

Hi, I'm quite new to scripting and I want to modify following line of an existing script: MYVAR=`subst |grep 'L:\\\:' | sed -e 's/.*\\\//'`; What I have to do is to use the content of a variable instead of the constant expression 'L:\\\:' as the grep string to be matched. Assuming I already... (5 Replies)
Discussion started by: snowbiker99
5 Replies

3. Shell Programming and Scripting

how to store grep command in a Variable

I have a variable A echo $A 5060 I am exporting the value X,Y,Z and it id fetching right thing and When I run C=`${X} -l ${Y} ${Z} "trap '' INT;. ~/.profile >/dev/null 2>/dev/null; netstat -na | grep \$A`" here it is going to same directory and also running netstat -na | grep 5060 ... (4 Replies)
Discussion started by: madhusmita
4 Replies

4. Shell Programming and Scripting

read in variable data from another file - grep

Hello! I think this should be an easy solution. I have a large file with many fields of data. The first field has a unique identifier (a subject number) for every record for a chunk of data. Something like this: There were ten experimental conditions (ec), but the ec is identified by only... (11 Replies)
Discussion started by: ccox85
11 Replies

5. Shell Programming and Scripting

Grep to return a code from accessing variable file name

All I want to do is find out if the string 'NO' is in a file by checking for a return code of 0 if there is a match. The grep works fine on the command line directly naming the file but I am obviously not using the correct syntax within the shell script as I consistently get the error message ... (5 Replies)
Discussion started by: SusanDAC
5 Replies

6. Shell Programming and Scripting

Grep Variable From File

Hey guys, I'm attempting to compare the contents of two files that are not identical on a Solaris 10 box. We are under audit and I need to do some comparisons of our application accounts with our unix accounts. I essentially want to pull a line from one file and search the second for an equal... (1 Reply)
Discussion started by: kaledragule
1 Replies

7. Shell Programming and Scripting

(BASH) Using a loop variable to grep something in a file?

Hi, I have a loop running until a variable L that is read previously in the full script. I'd like to grep some information in an input file at a line that contains the value of the loop parameter $i. I've tried to use grep, but the problem is nothing is written in the FILE files. It seems grep... (5 Replies)
Discussion started by: DMini
5 Replies

8. Shell Programming and Scripting

Directing cat or grep command in variable

Hi, I still have the problem with directing information from cat or grep to a variable. For instance: XMSG "$(date +%Y_%m_%d)_error_report.txt" "$(cat "$(date +%Y_%m_%d)_error_report.txt")" &Works! The text received by cat is directed to my function. If it is written like this, my... (2 Replies)
Discussion started by: haukee
2 Replies

9. Shell Programming and Scripting

Grep command to find string in Variable in file2

Hi , I am executing 2 queries and output is saved in file1.txt and file2.txt example of file1.txt Testing word Doc.docx,/Lab/Development and Validation/Multitest/MT_010708/Testing,Development and Validation,root,11-Mar-2014,,,,, Testing Excel _.xlsx,/Lab/Development and... (3 Replies)
Discussion started by: Sunil Mathapati
3 Replies

10. Shell Programming and Scripting

Issue using empty variable in grep command

Hi, I'm writing a shell script and trying to grep a variable value, it works fine as long as there is a value in /tmp/list.out which is captured in $DSK but sometimes the file tends to be empty and that is where I'm having an issue while using grep which returns nothing. I know I can use something... (15 Replies)
Discussion started by: mbak
15 Replies
NCO(1)							      General Commands Manual							    NCO(1)

NAME
NCO - netCDF Operators SYNTAX
operator [ options] input-files output-file DESCRIPTION
The netCDF Operators, or NCO are a suite of programs known as operators. Each operator is a standalone, command line program which is exe- cuted at the UNIX shell-level like, e.g., ls or mkdir. The operators take netCDF (<http://www.unidata.ucar.edu/packages/netcdf>) files as input, then perform a set of operations (e.g., deriving new data, averaging, hyperslabbing, or metadata manipulation) and produce a netCDF file as output. The operators are primarily designed to aid manipulation and analysis of gridded scientific data. The single command style of NCO allows users to manipulate and analyze files interactively and with simple scripts, avoiding the overhead (and some of the power) of a higher level programming environment. The NCO User's Guide illustrates their use with examples from the field of climate mod- eling and analysis. The available operators are: ncap2, netCDF Arithmetic Processor ncatted, netCDF Attribute Editor ncbo, netCDF Binary Operator (includes ncadd, ncsubtract, ncmultiply, ncdivide) ncea, netCDF Ensemble Averager ncecat, netCDF Ensemble Concatenator ncflint, netCDF File Interpolator ncks, netCDF Kitchen Sink ncpdq, netCDF Permute Dimensions Quickly, Pack Data Quietly ncra, netCDF Record Averager ncrcat, netCDF Record Concatenator ncrename, netCDF Renamer ncwa, netCDF Weighted Averager. (Note that the "averagers" are misnamed because they perform many non-linear operations as well, e.g., total, minimum, maximum, RMS). The operators are as general as netCDF itself: there are no restrictions on the contents of the netCDF file(s) used as input. NCO's inter- nal routines are completely dynamic and impose no limit on the number or sizes of dimensions, variables, and files. NCO is designed to be used both interactively and with large batch jobs. The default operator behavior is often sufficient for everyday needs, and there are numerous command line (i.e., run-time) options, for special cases. NCO works well on all modern operating systems. AUTHOR
NCO manual pages written by Charlie Zender and Brian Mays. REPORTING BUGS
Report bugs to <http://sf.net/bugs/?group_id=3331>. COPYRIGHT
Copyright (C) 1995-2010 Charlie Zender This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for NCO is maintained as a Texinfo manual called the NCO User's Guide. Because NCO is mathematical in nature, the documentation includes TeX-intensive portions not viewable on character-based displays. Hence the only complete and authoritative versions of the NCO User's Guide are the PDF (recommended), DVI, and Postscript versions at <http://nco.sf.net/nco.pdf>, <http://nco.sf.net/nco.dvi>, and <http://nco.sf.net/nco.ps>, respectively. HTML and XML versions are available at <http://nco.sf.net/nco.html> and <http://nco.sf.net/nco.xml>, respectively. If the info and NCO programs are properly installed at your site, the command info nco should give you access to the complete manual, except for the TeX-intensive portions. ncap2(1), ncatted(1), ncbo(1), ncdiff(1), ncea(1), ncecat(1), ncflint(1), ncks(1), nco(1), ncpdq(1), ncra(1), ncrcat(1), ncrename(1), ncwa(1) HOMEPAGE
The NCO homepage at <http://nco.sf.net> contains more information. NCO(1)
All times are GMT -4. The time now is 04:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy