The UNIX and Linux Forums  
Hej och välkommen från USA till UNIX och Linux Forum! Tack för ditt besök och gå med i vår globala gemenskapen.

Go Back   UNIX och Linux Forum > Särskilda Forum > UNIX Desktop for Dummies Frågor & Svar
.
google unix.com



UNIX Desktop for Dummies Frågor & Svar Diskutera UNIX och Linux användargränssnitt gillar GNOME, KDE, CDE och Open Office här. Alla UNIX och Linux Newbies Välkommen!

Mer UNIX och Linux Forum Ämnen Du kan hitta Helpful
Tråd Thread Starter Forum Svar Senaste Inlägg
Ändra en kolumn i avgränsad fil kolumnen till fast bredd kolumn manneni Prakash Shell-programmering och Skript 5 06-22-2009 06:27
Jämför 2 filer till en enda kolumn och produktion skillnader samit_9999 UNIX for Dummies Frågor & Svar 1 04-23-2008 01:02
Kan vi använda "tr"-kommandot för att skriva ut 5:e kolumnen i produktionen av "ls-l ' Nidhi2177 Shell-programmering och Skript 4 09-17-2007 07:53
Sub. nummer i kolumn av produktionen med Om ja156194 Shell-programmering och Skript 11 02-12-2007 01:52
flaggorna för att undertrycka kolumn produktion, # rader valda i DB2 SQL i UNIX jerardfjay Shell-programmering och Skript 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 Sök i denna tråd Rate Thread Visningslägen
  #1 (permalänk)  
Old 11-02-2008
handband2 handband2 is offline
Registered User
  
 

Join Date: Nov 2008
Inlägg: 5
Loop kolumn produktion

Jag behöver hjälp med det att göra med en bash-script? Jag försöker köra ett kommando för att mata ut data från en tabell och sedan in den i kommandon. Looping för varje rad med data.

Till exempel utdata från en tabell:

Kod:
10 John house
20 Jane apt
30 Joe townhome
Då måste jag ta ut från de uppgifter och för in den i ett annat kommando, så till exempel min produktion skulle kunna se ut:

Kod:
-----
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
Koden jag har är:
Kod:
#!/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
Resultatet är:
Kod:
-----------------------------------------------------------------

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 någon hjälpa eller peka mig var att åka på hur man gör detta?

Tack!
  #2 (permalänk)  
Old 11-03-2008
rubin's Avatar
Rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Inlägg: 321
Du kan arbeta med något sådant,

Kod:
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

Kod:
-----
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

Komihåglista

Thread Tools Sök i denna tråd
Sök i denna tråd:

Avancerad sökning
Visningslägen Betygsätt denna tråd
Betygsätt denna tråd:

Utstationering Regler
Du får inte efter nya trådar
Du får inte efter svar
Du får inte skicka bilagor
Du får inte redigera dina inlägg

BB-kod är
Smilies är
[IMG] kod
HTML-koden är Av
Trackback är
Pingbacks är
Refbacks är




Alla tider är GMT -4. Klockan är nu 08:35.


Powered by: vBulletin, Copyright © 2000 - 2006, Jelsoft Enterprises Limited. Översättningar Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
UNIX och Linux Forum Innehållet upphovsrättsskyddat © 1993-2009. All Rights Reserved.Ad förvaltning RedTyger

Content Relevant webbadresser från vBSEO 3.2.0