doesn't work --> Error messages: "grep: 0/0 RAID1 Optl: No such file or directory" and "grep: 1/1 RAID1 Optl: No such file or directory"
BUT
works as expected. But I would prefer to work with the $line-variable.
Sorry, but you set yourself up for that: it usually works as soon as you do it right. ;-))
Seriously: grep expects its arguments in the form (i simplify to the relevant here): grep <pattern> <file>. What you fed it instead, though, is: grep <pattern> <variable, that is: string which to search for pattern>. This is why grep treated the string you wanted to be searched as a filename - and of course this filename is not found, which is why you got the error of "file not found".
There is in fact another form of grep-invocation, where you can feed grep something from <stdin>, like this:
To get your string there is possible but you first have to create a process with the string as output. Can you guess which process that could be?
Yes, of course: echo "$variable". Therefore, here is your solution:
Picture grep as a machinery which has two different intakes: a file or <stdin>. Just like a coffee machine might have two intakes, one for ground coffee and one for whole beans. Which one is selected depends on how it is invoked. But you cannot pour your data into the wrong intake and then expect grep to do it right: put your beans into the opening for ground coffee and the coffee machine will make all sorts of things but probably not coffee.
I hope this helps.
bakunin
PS: CR/LF line endings are indeed important and will confuse a lot of UNIX utilities. I suggest to correct them to UNIX newlines first thing. There are unix2dos and dos2unix, two utilities which change back and forth from/to UNIX-style line breaks from/to DOS-style line breaks, sed-scripts and many other ways of achieving the same.
PPS: you do not need to create a temporary file at all in your code: as i have shown you you can directly work with the variable content.
The command structure is
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
.
Thank you so much for the solution. A solution I never would have found by myself.
Bankunin, its to early in the morning in Germany, so I only could test with $line and grep. Later on this weekend I will test the same solution with the temporary file.
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)
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)
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)
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)
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)
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)
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)
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)
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)