First consider the following script stored in a file named tester:
From your description of how """string""" works, the variable expansion $IAm and the command substitution $(who am i) should not occur in the assignments to var1 and var3, but should occur in the assignment to var2. But, as RudiC said and according to the standards and the bash man page, the above construct is a concatenation of an empty string (""), the evaluation of "string" (including parameter expansions, command substitutions, and arithmetic expansions), and another empty string (""). In other words, """string""" produces exactly the same results as
no matter how many <newline> characters are contained in string (as long as there are no unquoted double-quote characters in string).
On my system, running the above code produces the output:
Note also that all of the assignments in the above script produce an empty line as the first line in each of the assignments to var1, var2, and var3. If you don't want to include an empty line and don't want variable expansions, command substitutions, or arithmetic expansions to be performed in a variable intended to contain three lines, you should use single quotes like this:
Moving on. As RudiC said, this question has been asked many times before, except that your input is in shell variables instead of in files. (Although you have not given any reason that makes sense to me as to why you are hard-coding the values of these variables into strings instead of the storing the output produced on the various servers and your expected configuration values in files instead.) The diff utility would not be a way to compare two files unless all lines that you are comparing are guaranteed to always appear in the same order if they are present. But, you might want to consider:
But, grep won't work the way you need it to when you have empty lines in one or both of your files (and you have an empty line as the 1st line in both of your variables).
But what you want can be done with one invocation of awk:
which produces the output:
But the order in which input lines appear in the output may vary with different versions of awk. (And, note that the leading comma in the valid= line indicates that there is an empty line in both $var1 and $var2.)
This User Gave Thanks to Don Cragun For This Post:
I am trying to parse iostat output for io issues..
I want to print all lines including second occurance of 'extended' till EOF(end of file). Can we do that using awk or sed one liners or do we need a script for it? (1 Reply)
Ok so I can use awk to match a pattern and print the whole line with print $0. Is there any way to just tell awk to print every line of output when the pattern matches?
I'm having it wait for the word error and then print that entire line. But what I actually need to see is all the following... (9 Replies)
I am using Solaris, I want to print
3 lines before pattern match
pattern
5 lines after pattern match
Pattern is abcd to be searched in a.txt. Looking for the solution in sed/awk/perl. Thanks ..
Input File a.txt:
=================
1
2
3
abcd
4
5
6
7
8 (7 Replies)
Hi, I have this file.
close
block3c
block3b
block3a
open
close
block2b
block2a
open
close
block1a
open
and I need :
open
block3a
block3b
block3c
close (1 Reply)
I need to print the lines that do not match a pattern. I tried using grep -v and sed -n '/pattern/!p', but both of them are not working as I am passing the pattern as variable and it can be null some times.
Example
........ abcd......
.........abcd......
.........abcd......... (4 Replies)
I am getting the varible value from a grep command as:
var=$(grep "Group" File1.txt | sed 's/Group Name*//g;s/,//g;s/://g;s/-//g')
which leaves me the value of $var=xyz.
now i want to append $var value in the begining of all the lines present in the file. Can u please suggest?
Input file:
1... (10 Replies)
URGENT HELP IS NEEDED!!
I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but
- Currently, script is not printing lines to File3.txt in order.
- Also the matching lines are not moving out of File1.txt
... (1 Reply)
Hello,
I have a file contains two columns. I need to print the lines after “xxx” so i'm trying to match "xxx" & cut the lines after that. I'm trying with the grep & cut command, if there any simple way to extract this please help me.
Sample file :
name id
AAA 123
AAB 124
AAC 125... (4 Replies)
I have input file as below I need to check for a pattern and if it is there in file then I need to print all the lines below BEGIN and END keyword. Could you please help me how to get this in AIX using sed or awk.
Input file:
ABC
******** BEGIN *****
My name is Amit.
I am learning unix.... (8 Replies)