grep does not take pattern from file - linux

I have a pattern file, say t.txt, containing the following:
vali
and the file I want to run grep against, say a, containing the following:
validate
validate:
bw_validate:
[echo] Validating project: CrossService_v1_59_5_1
[echo] Found 62 errors and 28 warnings
[echo] -----------------------------------------------------------------
[echo] Validating project: CRM-UDB_59_4_2
[echo] Found 25 errors and 28 warnings
[echo] -----------------------------------------------------------------
[echo] Validation Failed: At least one project contains errors.
notify:
BUILD FAILED
bw.xml:311: Validation Failed: At least one project contains errors.
if I execute:
grep -iE vali a
I get the expected output, i.e.:
validate
validate:
bw_validate:
[echo] Validating project: CrossService_v1_59_5_1
[echo] Validating project: CRM-UDB_59_4_2
[echo] Validation Failed: At least one project contains errors.
bw.xml:311: Validation Failed: At least one project contains errors.
but if I execute:
grep -iE -f t.txt a
I don't get any match.
files are readable and both in the same directory (from which I execute the command).
I tried both with -f and --file=t.txt, --file='t.txt', --file="t.txt"
I'm on linux Fedora 16 64bit. Strangely enough, the same command works properly in windows with the grep/egrep porting.
Am I missing something?
Any help is appreciated as this is giving me an headache :(
thanks!

It should work right (it works for me). The -f switch is specified by POSIX.
The fact that you say it's working on Windows gave me an idea: Could it be the t.txt file ends with a DOS newline? I tried it with a clean file (no newline), and it worked. Then I tried it with a DOS file, and I was able to reproduce your results.
Try dos2unix to "fix" DOS files.

If you don't have the dos2unix utility then you can do any of the following to convert DOS or Windows newlines to Unix newlines.
This one-liner assumes that all lines end with CR+LF (carriage return + line feed)
sed -i 's/.$//' filename
You can usually enter the ^M control char literally on the command line by first pressing Ctrl-v (control key + v key) and then Ctrl-m.

sed -i 's/^M$//' filename
This following one-liner assumes that we are using GNU sed. The hex value for CR is 0x0D.
sed -i 's/\x0D$//' filename

Related

How do I suppress the md5sum FAILED --check warning but still get the output?

If I have a file named file1. And I then make an md5 file for file1, I then change the contents of file1, so the md5 is different. When I run a checksum on it, I will get
/home/student/.trashCan/file1: FAILED.
This is what I want, however i also get
md5sum: WARNING: 1 computed checksum did NOT match
How would i suppress this warning? So that i can get output from:
/home/student/.trashCan/file1: FAILED
/home/student/.trashCan/file2: OK
md5sum: WARNING: 1 computed checksum did NOT match
$student#osboxes
To this:
/home/student/.trashCan/file1: FAILED
/home/student/.trashCan/file2: OK
$student#osboxes
If i use the --status flag, it will supress the warning but also the output. And if i use grep/awk/cut then i get my output, but i also get the warning.
The problem is that the output from md5sum is two parts:
$ md5sum --check test.txt.md5
test.txt: FAILED
md5sum: WARNING: 1 computed checksum did NOT match
The first test.txt: FAILED line is sent to standard output. However, the second line, that starts with md5sum is sent to standard error. So, you can fix this by issuing your command this way:
$ md5sum --check test.txt.md5 2>/dev/null
test.txt: FAILED
This works because you're specifically telling it to send stderr to /dev/null. stdout will still be displayed correctly.

vim change base of relative path to source to other dir

I have a local Makefile which simply calls make -C ... As a result I get the output from the compiler with filenames and path to the directory relative to ...
Now vim isn't able to get the correct path for quickfix.
Q: How can I set the base path for vim quickfix to .. ?
My path structure:
<bla>/base/proj1/<localMakeFile>
<bla>/base/<globalMakefile>
<bla>/src/source1.cpp
I compile inside /base/proj1/
Compiler output for a error is like:
src/source1.cpp|141 col 54| Error: ....
But I am working in
/proj1/ so vim is unable to get the file src/source1.cpp
EDIT:
I see that the problem is basically related to the output of gnu make
make[4]: Entering directory '<bla>/...'
which is not parsed correctly if I use not an English environment. Setting the shell with export LANG= all works fine.
Q: Can vim parse also the German output of gnu make?
Appending the localized version with set errorformat+=<localized version> should work.
I am not aware that VIM supports it out of the box. After looking at the output of :set errorformat, which on my machine is a scary...
errorformat=%*[^"]"%f"%*\D%l: %m,"%f"%*\D%l: %m,%-G%f:%l: (Ea
ch undeclared identifier is reported only once,%-G%f:%l: for ea
ch function it appears in.),%-GIn file included from %f:%l:%c:,
%-GIn file included from %f:%l:%c\,,%-GIn file included from %f
:%l:%c,%-GIn file included from %f:%l,%-G%*[ ]from %f:%l:%c,%-G
%*[ ]from %f:%l:,%-G%*[ ]from %f:%l\,,%-G%*[ ]from %f:%l,%f:%l:
%c:%m,%f(%l):%m,%f:%l:%m,"%f"\, line %l%*\D%c%*[^ ] %m,%D%*\a[%
*\d]: Entering directory %*[`']%f',%X%*\a[%*\d]: Leaving direct
ory %*[`']%f',%D%*\a: Entering directory %*[`']%f',%X%*\a: Leav
ing directory %*[`']%f',%DMaking %*\a in %f,%f|%l| %m
...and by changing the output of the build process from
make: Entering directory `<directory>`
to
make: Entering `<directory>`
i got it to work by extending errorformat like this:
:set errorformat+=%D%*\\a:\ Entering\ %*[`']%f'

Error found when loading /etc/profile/

When I turn on my laptop(Ubuntu 14.04),appears
Error found when loading /etc/profile:\n\n/etc/profile.d/myenv_vars.sh:line
LD command not found
What should I do? Can I delete profile.d?
Your file should have
LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
"space" is not a valid character for shell variable names.
To avoid the trailing colon:
LD_LIBRARY_PATH=/usr/local/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
If LD_LIBRARY_PATH is null or unset, the new value will be just "/usr/local/lib"
If LD_LIBRAY_PATH has a value, the new value will be "/usr/local/lib:old_value"
If the first line of the file contains:
#!/bin/sh
but the file has cr/lf line endings, you will get this error. Do this:
# dos2unix /etc/profile.d/env_vars.sh
and try logging in again:
$ exec ${SHELL} -l
Should be no errors.

!#/bin/bash: No such file or directory

First, I run
/bin/bash a.sh
It succeed.
But when I want to run
/bin/bash a.sh > a_info.txt
It failed.
Error: line 1: !#/bin/bash: No such file or directory
It does not seem that it’s '^M' that’s causing this error.
The shebang pattern is #!/bin/your_shell, not !#/bin/your_shell. Just fix the typo.
Check the file's encoding.
If you get this error, but you did not misspell the 'shebang', have a close look at the file's encoding. I was getting this error on a file with encoding 'UTF8 with BOM'... I guess the BOM (Byte Order Mark) was causing the problem. Changed the encoding to ASCII and that fixed it (or you can use 'UTF-8 without BOM' which is effectively the same for files only containing ASCII characters).
Another possible cause of the "No such file or directory" error is if your shell script is using CRLF instead of LF line endings.

Error running make: missing separator (did you mean TAB instead of 8 spaces?)

I'm trying to get PHP phar command line tool installed on my Debian VM, how here described:
(1) download the php-src, I assume it's in /tmp/php/src
(2) make the dir /tmp/phar
(3) Save this as /tmp/php-src/ext/phar/Makefile.
(4) cd /tmp/php-src/ext/phar
(5) run sudo make
Now after step 5 I get an error:
:/tmp/php-src/ext/phar# make
Makefile:11: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.
As I know, there can be two possible causes for this error message:
Tabs in the make file. I've tested the file with od -t c Makefile. The file contains no tabs (\t).
It could be a bug of make v3.81 and need a patch or an upgrade to (yet instable: "Warning: This package is from the experimental distribution.") v3.82. I've downloaded and istalled (dpkg -i make_3.82-1_amd64.deb) it, but the error is still occuring.
What causes the error? How can it be avoided?
Thx
(Answered in a comment: See Question with no answers, but issue solved in the comments (or extended in chat))
#Beta wrote:
The line should begin with a tab, not a bunch of spaces.
The OP wrote:
I've replaced all 8-spaces sequences with tabs and can execute the make script now.
I used:
cat Makefile|sed "s/ /\t/" > Makefile

Resources