Grep trouble in Bash

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Grep trouble in Bash
# 1  
Old 01-22-2017
Grep trouble in Bash

Code:
PH=(6H 0 0 JD 9S 0 KD 0)        #input from .txt file

In the above array, I am trying to get the computer to tell me at what indices the non-zeros are at.

I don't understand why this doesn't work...

Code:
grep -v -b "0" ph.txt > position.txt

Isn't grep -v supposed to show non matches in Bash?

Could someone please clarify.

Cogiz

Last edited by Don Cragun; 01-22-2017 at 08:56 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 01-22-2017
The grep -b option is not covered by the standards, and you haven't told us what OS or version of grep you're using. So grep -b and grep -v -b may do something completely different on your system from what it does on mine (which uses a grep from a BSD). With a BSD grep, the command:
Code:
grep -b 0 file

will print lines from file that contain the character 0 with each line preceded by the byte offset from the start of the file of the first byte on that line and a colon. And, the command:
Code:
grep -v -b 0 file

will print lines from file that do NOT contain the character 0 anywhere in that line with each line preceded by the byte offset from the start of the file of the first byte on that line and a colon.
# 3  
Old 01-23-2017
In short, grep is an external command which operates on files and streams, it does not directly read from arrays.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trouble with tail and grep

Good Morning, i ran into some trouble this morning while 'improving' my monitoring stuff. i would like to get a warning when the number of mails sent (outbound) by postfix is above a certain number. so far, so easy. to test that i simply put cat /var/log/mail.info | grep 'to=<' | grep -v -e... (1 Reply)
Discussion started by: Mike
1 Replies

2. OS X (Apple)

Having trouble creating an alias for grep

Hi, I'm using Mac 10.9.1. I would like to create an alias for grep so that it won't print out messages like "grep: /Users/davea/workspace/myproject/subdir/: Is a directory" all the time. So in my terminal, I opened ~/.profile and entered alias grep='grep -s' However, when I close and... (5 Replies)
Discussion started by: laredotornado
5 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Having trouble with simple grep search

I have a text file (allWords.txt), that I would like to search through. Here is a snippet of what it looks like... a aah aahed aahing aahs aardvark aardvarks aardwolf ab abaci aback abacus abacuses abaft ...... I would like to use the grep search to search, line by line, for... (8 Replies)
Discussion started by: blackvelvet
8 Replies

4. Shell Programming and Scripting

Having a little trouble with grep

I am trying to make a script that has grep finding lines that I get from the cat command, that start with something and end with an argument. I can get the first part, but whenever I try to add on the part that looks at the end of the line too, it stops working. Any ideas why? Here is my script: ... (11 Replies)
Discussion started by: sammythesp3rmy
11 Replies

5. Shell Programming and Scripting

Having trouble with My Bash Script, need Help debugging

Hello Friends I am having trouble with my script below. I will describe the problems below the code box. I am hoping that some of the experts here can help me. #!/bin/bash #========================================================================================================= # Rsync File... (8 Replies)
Discussion started by: jdavis_33
8 Replies

6. Shell Programming and Scripting

Emergency grep/delete trouble!!!

Hi everyone, thank you so much for reading. I built a user reference page from /etc/password for a class project. Now I need two shell scripts: 1) Add names to the reference page 2) Delete names from the reference page. I know grep -v is involved somehow and some piping but I am super stuck. ... (1 Reply)
Discussion started by: jsmpdx
1 Replies

7. Shell Programming and Scripting

Quoting issue: Trouble with bash strings in script

I can do this on the command line: sqsh -S 192.168.x.x -o tmp -U user -P fakepass -D horizon -C "\ select second_id from borrower where btype like '%wsd%' " I can also just leave the SQL at the end intact on one line .... ... However, when I throw this in a script like: $SQSH -o... (4 Replies)
Discussion started by: Bubnoff
4 Replies

8. Shell Programming and Scripting

grep : having trouble with a single quote

Hi, I search for the string below which contains a single quote, some text '/home/myuser in the file myfile.txt as another user with the grep command as follows su - myuser -c "grep 'some text \'/home/myuser' myfile.txt" I also tried using two backslashes su - myuser... (6 Replies)
Discussion started by: cimcmahon
6 Replies

9. Shell Programming and Scripting

Bash Script: Trouble unable to run

I am trying to create a menu, and the script fails on ln 38 (Files in pwd). Any idea on where the problem is?? Thanks for the help Rob #!/bin/bash # Cool Script for Weekly Assignment 2 (#3) that creates a menu to act as a ui # and run some popular commands. clear while : do ... (9 Replies)
Discussion started by: rchirico
9 Replies

10. Shell Programming and Scripting

Trouble with grep again :(.. URGENT plss!

Frenz, I have a file with certain columns from ls -lR which looks something like: file stemp ---------- lrwxrwxrwx ./temp/s1 -> 2.ksh lrwxrwxrwx ./temp/s2 -> 3.ksh lrwxrwxrwx ./temp/subtemp/s3 -> 1.ksh lrwxrwxrwx ./temp/subtemp/s4 -> 2.ksh lrwxrwxrwx ./temp/s5 -> ... (9 Replies)
Discussion started by: manthasirisha
9 Replies
Login or Register to Ask a Question