You are not logged in.
Pages: 1
Does anyones know a way to speedup this process.
I have 3 files that i want juxtaposed. example, 3 files with name lastname age. I want at person to get the names and lastname and age.
while [ $counter -lt $CountLine ]; do
head1=`cat $Name | head -n $counter | tail -n 1`
head2=`cat $Lastname | head -n $counter | tail -n 1`
head3=`cat $Age | head -n $counter | tail -n 1`
echo "$counter"
echo "$head1 $head2 $head3" >> $DIR9
let counter+=1
done
I want something faster cause with 7000 entry it last for 2 minutes.
Last edited by j2lapoin (2015-08-05 22:56:59)
Offline
I don't know what exactly do you mean. Can you provide some examples of these 3 files?
See also 'man paste'.
When posting configs, code or command output, please use [ code ] tags https://bbs.archlinux.org/help.php#bbcode
like this
It makes the code more readable and - in case of longer listings - more convenient to scroll through.
Offline
3 files with 3 differents topic (name, lastname, age)
in the first file name name: in the second file name lastname: in the last file name age
john lewis 12
peter bacon 89
cayle douglas 67
fred lapointe 33
by concatenation or juxtaposition, i want in the name file person, name lastname and age on the same line.
john lewis 12
peter bacon 89
cayle douglas 67
...
..
.
I made a first attempt, it was successfull but it take 2 minutes to go on, way too long.
while [ $counter -lt $CountLine ]; do
head1=`cat name | head -n $counter | tail -n 1`
head2=`cat lastname | head -n $counter | tail -n 1`
head3=`cat age | head -n $counter | tail -n 1`
echo "$counter"
echo "$head1 $head2 $head3" >> person
let counter+=1
done
Offline
Did you read that man page?
$ paste name lastname age
john lewis 12
peter bacon 89
cayle douglas 67
fred lapointe 33
$ paste name lastname age | column -t
john lewis 12
peter bacon 89
cayle douglas 67
fred lapointe 33
Offline
Did you read that man page?
$ paste name lastname age john lewis 12 peter bacon 89 cayle douglas 67 fred lapointe 33 $ paste name lastname age | column -t john lewis 12 peter bacon 89 cayle douglas 67 fred lapointe 33
PERFECT! I forgot about it. thanks.
Offline
If it shall be faster, the best way is probably to not use bash but for example C instead.
I have just realized, that what karol suggested, paste, should do exactly what you want.
Because like this, for every line of every file the commands you use do essentially the following in the background:
- open the file
- search for the nth line
- close the file
Furthermore you use three different programs for this, which does also slow down the operation, because they were not designed to be used with the respective others.
As far as I understand, you have three files, one of them has all the first names, another one all the last names, and the last one all the ages, where every nth line of one file corresponds to the nth line of any of the two others.
Your script does simplify these three files by merging them into one with three space separated columns, am I right?
So the question arising is - why? Where do the former files come from? Did you create them yourself? If so, why don't directly create them in a different manner?
EDIT: way too slow.
Last edited by respiranto (2015-08-05 22:50:25)
Offline
Just to prove no magic is involved:
$ ls
age lastname name
$ head *
==> age <==
12
89
67
33
==> lastname <==
lewis
bacon
douglas
lapointe
==> name <==
john
peter
cayle
fred
Please remember to mark the thread as solved https://bbs.archlinux.org/viewtopic.php?id=130309
Offline
See also 'man paste'.
To clarify, I'd strongly recommend executing that command rather than googling that phrase!
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
To clarify, I'd strongly recommend executing that command rather than googling that phrase!
... and my wife made me google...
Offline
Pages: 1