Sponsored Content
Top Forums Shell Programming and Scripting Grep command to ignore line starting with hyphen Post 302947557 by Aia on Thursday 18th of June 2015 07:28:16 PM
Old 06-18-2015
Quote:
Originally Posted by Srinraj Rao
Thanks for your quick response. My requirement is different.

The file contains text as follows.
#test
+abc
-xyz
real

The for loop has to read the file line by line and pass the string in each line to the do loop. While reading each line in the file, if the line starts with # or + or - that line should be ignored.
And still applies, if you care to continue using the same script model.
Code:
for TEST in $(awk '$1 ~ /^[^-#/+]/' "$FILE"); do
     something "$TEST"
done

However, the shell doesn't need awk or any external program in this case to do what you want.

Code:
while read line; do
   if [[ "$line" =~ ^[^-+#] ]]; then
        echo "Do something with $line"
   fi
done < "$FILE"

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

use of hyphen in #! line

In one script i have seen - in #! line can somebody explain the meaning of -(hyphen) here #! /bin/sh - (7 Replies)
Discussion started by: Dhruva
7 Replies

2. Shell Programming and Scripting

add a hyphen every 2 characters of every line

I have a text file like this with hundreds of lines: >cat file1.txt 1027123000 1027124000 1127125000 1128140000 1228143000 > all lines are very similar and have exactly 10 digits. I want to separate the digits by twodigit and hyphens....like so, > 10-27-12-30-00 10-27-12-40-00... (7 Replies)
Discussion started by: ajp7701
7 Replies

3. Shell Programming and Scripting

Grep from a starting line till the end of the file

Hi Folks, I got to know from this forums on how to grep from a particular line say line 6 awk 'NR==6 {print;exit}' But how do i grep from line 6 till the end of the file or command output. Thanks, (3 Replies)
Discussion started by: Mr. Zer0
3 Replies

4. UNIX Desktop Questions & Answers

How to remove text in each line after hyphen?

Hi, I'm trying to do something relatively simple. I have a txt file that has the following kinds of lines (and many more lines): CP19 Oahu - Maunawili Falls CP20 Oahu - Maunawili Falls AG12 Oahu - Maunawili Falls CP22 Oahu - Maunawili Falls, Local area AG14 Oahu CP141 KZ102 Kauai -... (7 Replies)
Discussion started by: euspilapteryx
7 Replies

5. Ubuntu

starting Places->Networks at command line

Hi All I have UBUNTU 10.04 I would like to run at command line the gui application that I use for finding network places and navigate shared folders or network driver. I mean the one located under menu PLACES->NETWORK I tried using "nautilus" but you need to know in advance which IP to give and... (2 Replies)
Discussion started by: manustone
2 Replies

6. Shell Programming and Scripting

Ignore the 255 character limit of command line

Hi I would just like to ask if there is a way for UNIX to ignore/overcome the 255 character limit of the command line? My problem is that I have a really long line of text from a file (300+ bytes) which i have to "echo" and process by adding commands like "sed" to the end of the line, like... (5 Replies)
Discussion started by: agentgrecko
5 Replies

7. UNIX for Dummies Questions & Answers

Grep only line starting with....

Hello, I have a command that show some application information. Now, I have to grep there informations, like: # showlog | grep 1266 1266.1369866124 :: 1266.1304711286 :: 41031.1161812668 :: 41078.1301266480 :: 41641.712662564 :: 1266.333792515 :: 41462.1512661988 :: 1266.54932671... (5 Replies)
Discussion started by: Lord Spectre
5 Replies

8. SCO

Grep to ignore suffix & find end of line

In COBOL, a hyphen can be used in a field name and in a specific program some field names would be identical to others except a suffix was added--sometimes a suffix to a suffix was used. For example, assume I am looking for AAA, AAA-BBB, and AAA-BBB-CCC and don't want to look at AAA-BBB-CCC... (7 Replies)
Discussion started by: wbport
7 Replies

9. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies

10. UNIX for Beginners Questions & Answers

Grep file starting from pattern matching line

I have a file with a list of references towards the end and want to apply a grep for some string. text .... @unnumbered References @sp 1 @paragraphindent 0 2017. @strong{Chalenski, D.A.}; Wang, K.; Tatanova, Maria; Lopez, Jorge L.; Hatchell, P.; Dutta, P.; @strong{Small airgun... (1 Reply)
Discussion started by: kristinu
1 Replies
PY.TEST-3(1)							      pytest							      PY.TEST-3(1)

NAME
pytest - pytest usage CALLING PY.TEST-3 THROUGH PYTHON -M PY.TEST-3 New in version 2.0. If you use Python-2.5 or later you can invoke testing through the Python interpreter from the command line: python -m pytest [...] This is equivalent to invoking the command line script py.test-3 [...] directly. GETTING HELP ON VERSION, OPTION NAMES, ENVIRONMENT VARIABLES py.test-3 --version # shows where pytest was imported from py.test-3 --funcargs # show available builtin function arguments py.test-3 -h | --help # show help on command line and config file options STOPPING AFTER THE FIRST (OR N) FAILURES To stop the testing process after the first (N) failures: py.test-3 -x # stop after first failure py.test-3 --maxfail=2 # stop after two failures SPECIFYING TESTS
/ SELECTING TESTS Several test run options: py.test-3 test_mod.py # run tests in module py.test-3 somepath # run all tests below path py.test-3 -k string # only run tests whose names contain a string Import 'pkg' and use its filesystem location to find and run tests: py.test-3 --pyargs pkg # run all tests found below directory of pypkg MODIFYING PYTHON TRACEBACK PRINTING
Examples for modifying traceback printing: py.test-3 --showlocals # show local variables in tracebacks py.test-3 -l # show local variables (shortcut) py.test-3 --tb=long # the default informative traceback formatting py.test-3 --tb=native # the Python standard library formatting py.test-3 --tb=short # a shorter traceback format py.test-3 --tb=line # only one line per failure DROPPING TO PDB (PYTHON DEBUGGER) ON FAILURES Python comes with a builtin Python debugger called PDB. py.test-3 allows one to drop into the PDB prompt via a command line option: py.test-3 --pdb This will invoke the Python debugger on every failure. Often you might only want to do this for the first failing test to understand a certain failure situation: py.test-3 -x --pdb # drop to PDB on first failure, then end test session py.test-3 --pdb --maxfail=3 # drop to PDB for the first three failures SETTING A BREAKPOINT
/ AKA SET_TRACE() If you want to set a breakpoint and enter the pdb.set_trace() you can use a helper: import pytest def test_function(): ... pytest.set_trace() # invoke PDB debugger and tracing In previous versions you could only enter PDB tracing if you disabled capturing on the command line via py.test-3 -s. PROFILING TEST EXECUTION DURATION
To get a list of the slowest 10 test durations: py.test-3 --durations=10 CREATING JUNITXML FORMAT FILES
To create result files which can be read by Hudson or other Continuous integration servers, use this invocation: py.test-3 --junitxml=path to create an XML file at path. CREATING RESULTLOG FORMAT FILES
To create plain-text machine-readable result files you can issue: py.test-3 --resultlog=path and look at the content at the path location. Such files are used e.g. by the PyPy-test web page to show test results over several revi- sions. SENDING TEST REPORT TO POCOO PASTEBIN SERVICE
Creating a URL for each test failure: py.test-3 --pastebin=failed This will submit test run information to a remote Paste service and provide a URL for each failure. You may select tests as usual or add for example -x if you only want to send one particular failure. Creating a URL for a whole test session log: py.test-3 --pastebin=all Currently only pasting to the http://paste.pocoo.org service is implemented. CALLING PY.TEST-3 FROM PYTHON CODE New in version 2.0. You can invoke py.test-3 from Python code directly: pytest.main() this acts as if you would call "py.test-3" from the command line. It will not raise SystemExit but return the exitcode instead. You can pass in options and arguments: pytest.main(['x', 'mytestdir']) or pass in a string: pytest.main("-x mytestdir") You can specify additional plugins to pytest.main: # content of myinvoke.py import pytest class MyPlugin: def pytest_addoption(self, parser): raise pytest.UsageError("hi from our plugin") pytest.main(plugins=[MyPlugin()]) Running it will exit quickly: $ python myinvoke.py ERROR: hi from our plugin AUTHOR
holger krekel at merlinux eu COPYRIGHT
2011, holger krekel et alii 2.2 June 24, 2012 PY.TEST-3(1)
All times are GMT -4. The time now is 11:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy