The UNIX and Linux Forums  
Hallo en welkom van de Verenigde Staten aan de UNIX en Linux Forum! Bedankt voor uw bezoek en Deelnemen aan onze wereldwijde gemeenschap.

Go Back   De Unix-en Linux Forum > Speciale Forums > UNIX Desktop voor Dummies Questions & Answers
.
google unix.com



UNIX Desktop voor Dummies Questions & Answers Bespreek UNIX en Linux gebruiker interfaces zoals GNOME, KDE, COB en Open Office hier. Alle UNIX-en Linux-Newbies Welkom!

Meer UNIX en Linux Forum Onderwerpen Misschien vindt u Helpful
Draad Thread Starter Forum Antwoorden Last Post
Veranderen van een kolom van delimited file kolom naar vaste breedte kolom manneni Prakash Programmeren en Shell Scripting 5 06-22-2009 05:27
Vergelijk 2 bestanden voor een enkele kolom en output verschillen samit_9999 UNIX voor Dummies Questions & Answers 1 04-23-2008 12:02
Kunnen we gebruik 'tr' commando om af te drukken 5e kolom van de output van 'ls-l' Nidhi2177 Programmeren en Shell Scripting 4 09-17-2007 06:53
Sub. nummers in de kolom van de output met Als ja156194 Programmeren en Shell Scripting 11 02-12-2007 01:52 PM
vlaggen te onderdrukken kolom output, # rijen geselecteerd in DB2 SQL in UNIX jerardfjay Programmeren en Shell Scripting 1 11-02-2005 06:48

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Zoeken in deze Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-02-2008
handband2 handband2 is offline
Geregistreerde gebruiker
  
 

Join Date: november 2008
Posts: 5
Loop kolom output

Ik heb hulp nodig in wat te doen met een bash-script? Ik probeer het uitvoeren van een commando naar de output van de gegevens uit een tabel en vervolgens plaatst u het in commando's. Looping voor elke rij van de gegevens.

Bijvoorbeeld de productie van gegevens uit een tabel:

Code:
10 John house
20 Jane apt
30 Joe townhome
Daarna heb ik nodig om de output van de gegevens en plaats deze in een ander commando, zodat bijvoorbeeld mijn output zou er als volgt uitzien:

Code:
-----
The number of the person is 10
The name of the person is John
John lives in a house
-----
The number of the person is 20
The name of the person is Jane
Jane lives in a apt
-----
The number of the person is 30
The name of the person is Joe
Joe lives in a townhome
De code die ik heb is:
Code:
#!/bin/bash

echo
echo "-----------------------------------------------------------------"

DATA=`cat data.txt`

for i in $DATA; do

    NUM=$(echo $i |awk '{print $1}');
    NAME=$(echo $i |awk '{print $2}');
    LOC=$(echo $i |awk '{print $3}');    

    echo "The number of the person is $NUM"
    echo "The name of the person is $NAME"
    echo "$NAME lives in a $LOC"

echo
echo "-----------------------------------------------------------------"
echo
done
De output is:
Code:
-----------------------------------------------------------------

The number of the person is 10
The name of the person is 
 lives in a 

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


The number of the person is John
The name of the person is 
 lives in a 

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


The number of the person is house
The name of the person is 
 lives in a 

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


The number of the person is 20
The name of the person is 
 lives in a 

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


The number of the person is Jane
The name of the person is 
 lives in a 

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


The number of the person is apt
The name of the person is 
 lives in a 

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


The number of the person is 30
The name of the person is 
 lives in a 

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


The number of the person is Joe
The name of the person is 
 lives in a 

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


The number of the person is townhome
The name of the person is 
 lives in a 

----------------------------------------------------------------
Kan iemand me helpen of het punt waar te gaan over hoe dit te doen?

Bedankt!
  #2 (permalink)  
Old 11-03-2008
rubin's Avatar
Rubin rubin is offline Forum Advisor  
Geregistreerde gebruiker
  
 

Join Date: november 2007
Posts: 321
U kunt werken op iets als dit,

Code:
while read line
 do 
   set -- $line
   # you can also use echo -e 
   printf -- "-----\nThe number of the person is $1\nThe name of the person is $2\n$2 lives in a $3\n"
 done < file
Output

Code:
-----
The number of the person is 10
The name of the person is John
John lives in a house
-----
The number of the person is 20
The name of the person is Jane
Jane lives in a apt
-----
The number of the person is 30
The name of the person is Joe
Joe lives in a townhome
Closed Thread

Bladwijzers

Thread Tools Zoeken in deze Thread
Zoeken in deze Thread:

Uitgebreid zoeken
Display Modes Beoordeel deze draad
Beoordeel deze draad:

Posting Regels
Jij mag niet Post Nieuwe threads
Jij mag niet na antwoorden
Jij mag niet post attachments
Jij mag niet bewerk uw berichten

BB code is Aan
Smilies zijn Aan
[IMG] code Aan
HTML-code is Uit
Trackbacks zijn Aan
Pingbacks zijn Aan
Refbacks zijn Aan




Alle tijden zijn GMT -4. Het is nu 03:03 PM.


Powered by: vBulletin, Copyright © 2000 - 2006, Jelsoft Enterprises Limited. Vertalingen Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
De Unix-en Linux Forums Copyright © 1993-2009. Alle rechten Reserved.Ad Beheer door RedTyger

Content Relevante URL's door vBSEO 3.2.0