Sponsored Content
Top Forums Shell Programming and Scripting Failure: if grep "$Var" "$line" inside while read line loop Post 303024308 by RudiC on Friday 5th of October 2018 05:50:36 PM
Old 10-05-2018
Welcome to the forum.


The command structure is
Code:
grep -options pattern file

That means the $line variable needs to hold a filename which it obviously doesn't. You could "grep" (pls. note the quotes - there may be better ways to check) a variable's contents like
Code:
echo $var | grep pattern

.
This User Gave Thanks to RudiC For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Programming

fgets read file line with "\n" inside

Hi, I have a string like this, char str ="This, a sample string.\\nThis is the second line, \\n \\n, we will have one blank line"; if I want to use strtok() to seperate the string, which token should I use? I tried "\n", "\\n", either not working. peter (1 Reply)
Discussion started by: laopi
1 Replies

5. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

6. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

7. Shell Programming and Scripting

Move a line containg "char" above line containing "xchar"

Okay, so I have a rather large text file and will have to process many more and this will save me hours of work. I'm not very good at scripting, so bear with me please. Working on Linux RHEL I've been able to filter and edit and clean up using sed, but I have a problem with moving lines. ... (9 Replies)
Discussion started by: rex007can
9 Replies

8. Shell Programming and Scripting

Bash - How to do a "read -p" inside a while loop?

Hi there guys! I was trying to do: while read line; do if ; then read -p "Press Enter to continue..." cont=0 fi echo $line let cont++ done < file.txt However, I have read that the read -p would not work in a while loop... I was wondering if there is any other way to... (2 Replies)
Discussion started by: rplae
2 Replies

9. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies
resize(1X)							     MIT X11R4								resize(1X)

Name
       resize - utility to set TERMCAP and terminal settings to current window size

Syntax
       resize [-u] [-s [row col]]

Description
       The  uitility  prints  a  shell command for setting the TERM and TERMCAP environment variables to indicate the current size of xterm window
       from which the command is run. For this output to take effect, resize must either be evaluated as part of the command  line  (usually  done
       with  a	shell alias or function) or else redirected to a file which can then be read in. From the C shell (usually known as /bin/csh), the
       following alias could be defined in the user's .cshrc:

	   % alias rs 'set noglob; `eval resize`'

       After resizing the window, the user would type:

	   % rs

       Users of versions of the Bourne shell (usually known as /bin/sh) that do not have command functions will need to send the output to a  tem-
       porary file and the read it back in with the ``.'' command:

	   $ resize >/tmp/out
	   $ . /tmp/out

Options
       The following options may be used with resize:

       -u      This option indicates that Bourne shell commands should be generated even if the user's current shell is not /bin/sh.

       -c      This option indicates that C shell commands should be generated even if the user's current shell is not /bin/csh.

       -s [rows columns]
	       This option indicates that the Sun console escape sequences will be used instead of the special xterm escape code. If rows and col-
	       umns are given, resize will ask the xterm to resize itself. However, the window manager may choose to disallow the change.

Restrictions
       The -u or -c must appear to the left of -s if both are specified.

       There should be some global notion of display size; termcap and terminfo need to be rethought in the context of window systems.	(Fixed	in
       4.3BSD, and ULTRIX-32 1.2)

Files
       For the base termcap entry to modify.

       User's alias for the command.

See Also
       csh(1), tset(1), xterm(1X)

																	resize(1X)
All times are GMT -4. The time now is 10:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy