perl -ane "print join(qq(\t),@F[0,1,20,21,2,10,12,14,11,4,5,6]).qq(\n)"
file.txt
-a autosplit mode with -n or -p (splits $_ into @F)
-n assume "while (<>) { ... }" loop around program 5 1147
Well, the python interpreter has no equivalent to -n or -a in the perl
interpreter. You'd have to implement it using an actual while loop and
because of the indention sensitivity in Python, I don't believe you can
do it on the command line. (I may be very wrong here, but I've not
gotten it to work).
--
Jerry
On Jan 24, 10:25 pm, "NoName" <zaz...@gmail.comwrote:
perl -ane "print join(qq(\t),@F[0,1,20,21,2,10,12,14,11,4,5,6]).qq(\n)"
file.txt
-a autosplit mode with -n or -p (splits $_ into @F)
-n assume "while (<>) { ... }" loop around program
At Thursday 25/1/2007 01:25, NoName wrote:
>perl -ane "print join(qq(\t),@F[0,1,20,21,2,10,12,14,11,4,5,6]).qq(\n)"
Must be done on a single line?
I'm not sure if I've got right the behavior - it's been some time
since I quit writing Perl code. The script iterates over all lines
contained on all files specified on the command line; for each line,
splits it on whitespace; then it prints a selected set of fields
(columns 0, 1, 20, 21...) using a tab character as field separator.
=== cut ===
import operator,fileinput
mapper = map(operator.itemgetter, [0,1,20,21,2,10,12,14,11,4,5,6])
for line in fileinput.input():
fields = line.split()
print '\t'.join(m(fields) for m in mapper)
=== cut ===
--
Gabriel Genellina
Softlab SRL
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! http://www.yahoo.com.ar/respuestas
Thanks;)
On 25 Янв., 17:47, Gabriel Genellina <gagsl...@yahoo.com.ar>wrote:
At Thursday 25/1/2007 01:25, NoName wrote:
perl -ane "print join(qq(\t),@F[0,1,20,21,2,10,12,14,11,4,5,6]).qq(\n)"Must be done on a single line?
I'm not sure if I've got right the behavior - it's been some time
since I quit writing Perl code. The script iterates over all lines
contained on all files specified on the command line; for each line,
splits it on whitespace; then it prints a selected set of fields
(columns 0, 1, 20, 21...) using a tab character as field separator.
=== cut ===
import operator,fileinput
mapper = map(operator.itemgetter, [0,1,20,21,2,10,12,14,11,4,5,6])
for line in fileinput.input():
Â* Â* Â*fields = line.split()
Â* Â* Â*print '\t'.join(m(fields) for m in mapper)
=== cut ===
--
Gabriel Genellina
Softlab SRL
__________________________________________________
Preguntá. Respondé. DescubrÃ*.
Todo lo que querÃ*as saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!http://www.yahoo.com.ar/respuestas
Gabriel Genellina:
import operator,fileinput
mapper = map(operator.itemgetter, [0,1,20,21,2,10,12,14,11,4,5,6])
for line in fileinput.input():
fields = line.split()
print '\t'.join(m(fields) for m in mapper)
I'm just curious, what's the advantage of using itemgetter there
compared to something simpler like this (untested!)?
import fileinput
positions = [0,1,20,21,2,10,12,14,11,4,5,6]
for line in fileinput.input():
fields = line.split()
print '\t'.join(fields[m] for m in positions)
Bye,
bearophile
<be************@lycos.comescribió en el mensaje
news:11**********************@v33g2000cwv.googlegr oups.com...
I'm just curious, what's the advantage of using itemgetter there
compared to something simpler like this (untested!)?
None!
--
Gabriel Genellina This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Olaf Meyer |
last post by:
I'm having some problems compiling Python 2.3.3 on HP-UX (B.11.00).
I've tried sevral different options for the configure script (e.g.
enabling/disabling gcc, aCC) but I always get the same problem...
|
by: Kurt B. Kaiser |
last post by:
Patch / Bug Summary
___________________
Patches : 259 open ( -5) / 2573 closed (+17) / 2832 total (+12)
Bugs : 745 open ( +0) / 4405 closed (+21) / 5150 total (+21)
RFE : 150 open...
|
by: Jerald |
last post by:
Running python 2.3.4 on valgrind (a tool like purify which checks
the use of uninitialized memory, etc), gives a lot of errors.
See below.
jfj@cluster:~/> python -V
Python 2.3.4...
|
by: Kurt B. Kaiser |
last post by:
Patch / Bug Summary
___________________
Patches : 241 open ( -6) / 2622 closed (+26) / 2863 total (+20)
Bugs : 764 open ( +6) / 4453 closed (+38) / 5217 total (+44)
RFE : 150 open...
|
by: Kurt B. Kaiser |
last post by:
Patch / Bug Summary
___________________
Patches : 391 open ( +7) / 3028 closed (+12) / 3419 total (+19)
Bugs : 906 open ( -3) / 5519 closed (+19) / 6425 total (+16)
RFE : 207 open...
|
by: Kurt B. Kaiser |
last post by:
Patch / Bug Summary
___________________
Patches : 420 open ( +4) / 3410 closed ( +2) / 3830 total ( +6)
Bugs : 915 open (+17) / 6186 closed ( +6) / 7101 total (+23)
RFE : 235 open...
|
by: Osiris |
last post by:
I have these pieces of C-code (NOT C++ !!) I want to call from Python.
I found Boost.
I have MS Visual Studio 2005 with C++.
is this the idea:
I write the following C source file:...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |