Sponsored Content
Top Forums Shell Programming and Scripting Breaking long lines into (characters, newline, space) groups Post 302316398 by ghostdog74 on Friday 15th of May 2009 01:08:19 AM
Old 05-15-2009
if you have Python, here's an alternative solution
Code:
import textwrap
t=textwrap.TextWrapper(subsequent_indent=" ",width=78)
for line in open("file"):
    for i in t.wrap(line):
        print i

output
Code:
# more file
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

# ./test.py
123456789012345678901234567890123456789012345678901234567890123456789012345678
 90123456789012345678901234567890123456789012345678901234567890123456789012345
 67890123456789012345678901234567890123456789012345678901234567890123456789012
 34567890

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remove trailing newline characters

Hello , I have the folowing scenario : I have a text file as follows : (say name.txt) ABC DEF XYZ And I have one more xml file as follows : (say somexml.xml) <Name>ABC</Name> <Age>12</Age> <Class>D</Class> <Name>XYZ</Name> <Age>12</Age> <Class>D</Class> <Name>DEF</Name>... (7 Replies)
Discussion started by: shweta_d
7 Replies

2. UNIX for Dummies Questions & Answers

non-breaking space question

Might anyone know how to make a nbsp (160|0xA0) character? I am using a Dell Latitude D620 running Windows XP and then starting Exceed 9.0 defaulting to native window emulation for my X (us.kbf keymapping) (Latin-1 symbol set I believe) and calling an xterm (fontdefault, whatever that might be)... (1 Reply)
Discussion started by: runmeat6
1 Replies

3. Shell Programming and Scripting

Replace long space to become one space?

Hi, i have the log attached. Actually i want the long space just become 1 space left like this : Rgds, (12 Replies)
Discussion started by: justbow
12 Replies

4. Ubuntu

Disk Space lost mysteriously upon breaking a process.

Hi All, Today when I was working on a script to generate custom wordlist. So I ran a script and the output was directed to /tmp. The disk space was around 19 gb. While the script was running, I decided to direct the o/p file to my 1TB drive. So I broke the run using Ctrl + C. Now when I... (4 Replies)
Discussion started by: morningSunshine
4 Replies

5. UNIX for Dummies Questions & Answers

Breaking up a text file into lines

Hi, I have a space delimited text file that looks like the following: BUD31 YRI 2e-06:CXorf15 YRI 3e-06:CREB1 YRI 4e-06 FLJ21438 CEU 3e-07:ETS1 CEU 8e-07:FGD3 CEU 2e-06 I want to modify the text file so that everytime there is a ":", a new line is introduced so that the document looks... (3 Replies)
Discussion started by: evelibertine
3 Replies

6. Shell Programming and Scripting

cutting long text by special char around 100 byte and newline

Regard, How can i cut the text by special char(|) around 100 byte and write the other of the text at newline using Perl. ... (3 Replies)
Discussion started by: Shawn, Lee
3 Replies

7. Shell Programming and Scripting

awk: searching for non-breaking-space

This code shal search for the non-breaking space 0xA0 though it returns the error "fatal: attempt to use scalar 'nbs' as array" Can somebody help? awk --non-decimal-data -v nbs="0xA0" '{if($0 in nbs) {print FILENAME, NR}}' *.txt (1 Reply)
Discussion started by: sdf
1 Replies

8. Shell Programming and Scripting

Breaking lines which contains more than 50 characters in a file

Hi, I have a file which contains many lines. Some of them are longer than 50 chars. I want to break those lines but I don't want to break words, e.g. the file This is an exemplary text which should be broken aaaaaa bbbbb ccccc This is the second line This line should also be broken... (3 Replies)
Discussion started by: wenclu
3 Replies

9. Shell Programming and Scripting

Newline characters in fields of a file

My source file is pipe delimeted file with 53 fields.In 33 rd column i am getting mutlple new line characters,dule to that record is breaking into multiple records. Note : here record delimter also \n sample Source file with 6 fields : 1234|abc| \nabcd \n bvd \n cde \n |678|890|900\n ... (6 Replies)
Discussion started by: lakshmi001
6 Replies

10. Shell Programming and Scripting

Mailx appending exclamation mark and newline in a long line

Hi, I have a shell script which automates reporting and at times, requires the report line to be very long (sometimes as long as 2131 chars). The output I get is similar to this: XXXX XXXXXXX 16:15 3.24% 5.07% 3.69% 5.23% 3.68% 4.06% 3.57% 5.03% 4.31% 5.11% 3.49% 4.19% 4.31% ... (2 Replies)
Discussion started by: gilberteu
2 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 03:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy