🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #7723

Re: "Transponer" u fichero de texto.

#7723
From: J.A. Gutierrez
Date: Tue, 11 Feb 2003 10:32
89 lines
2440 bytes
Han Solo <hsolo@escomposlinux.org> wrote:

: tengo un fichero de texto, supongamos algo como:

: a1 a2 a3 a4 a5
: b1 b2 b3 b4 b5
: c1 c2 c3 c4 c5
: d1 d2 d3 d4 d5
: e1 e2 e3 e4 e5

: y quiero convertirlo en su "transpuesto";

: a1 b1 c1 d1 e1
: a2 b2 c2 d2 e2
: a3 b3 c3 d3 e3
: a4 b4 c4 d4 e4
: a5 b5 c5 d5 e5

- Opcion A:

	Supongamos que tienes tu matriz de 3x3 en "file":

	tr ' ' \\012 < file | ./catsplit.sh 3 file.out | ed

	te dejara en file.out la matriz deseada.

- catsplit.sh -------------------------------------------------------------
#!/bin/sh

#
# use:
#	$0 numlines fileout < file | ed
#

rm -f $2

line=0
first_time=true

echo H
echo a
while read s
do
	if [ $line -eq $1 ]
	then
		if $first_time
		then
			echo .
			echo 1
			first_time=false
		else
			echo 1
		fi
		line=0
	fi
	if $first_time
	then
		echo $s
	else
		echo 's/$/ '"$s"'/'
		echo '+'
	fi

	line=`expr $line + 1`
done

echo w $2
echo q

---------------------------------------------------------------------------

- Opcion B:

(
cut -d" " -f1 file | tr \\012 " "; echo
cut -d" " -f2 file | tr \\012 " "; echo
cut -d" " -f3 file | tr \\012 " "; echo
) | sed 's/ $//'


- Otras mas eficientes:

usar algun lenguaje que soporte matrices.

-- 
PGP and other useless info at      \
http://www.cps.unizar.es/~spd/      \
finger://daphne.cps.unizar.es/spd    \       Timeo Danaos et dona ferentes
ftp://ivo.cps.unizar.es/pub/          \                         (Virgilio)   
Technical Details
Message-ID: <b2ajgb$b2c$1@news.unizar.es>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!news.rediris.es!bashful.rediris.es!news.unizar.es!not-for-mail
References: <873cn0hz9a.fsf@ietcc.csic.es>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII-7-bit
X-Google-Thread: f86c8,197d58af93fd12d4
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2003-02-11 01:54:59 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!news.rediris.es!bashful.rediris.es!news.unizar.es!not-for-mail
From: "J.A. Gutierrez" <spd@daphne.cps.unizar.es>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: "Transponer" u fichero de texto.
Date: 11 Feb 2003 10:32:43 GMT
Organization: Rank
Lines: 89
Message-ID: <b2ajgb$b2c$1@news.unizar.es>
References: <873cn0hz9a.fsf@ietcc.csic.es>
NNTP-Posting-Host: daphne.cps.unizar.es
X-Trace: news.unizar.es 1044959563 11340 155.210.152.20 (11 Feb 2003 10:32:43 GMT)
X-Complaints-To: usenet@news.unizar.es
NNTP-Posting-Date: 11 Feb 2003 10:32:43 GMT
User-Agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (IRIX/6.2 (IP22))