Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
bash: variable zeilenweise in file schreiben[solved]
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
Martini
Tux's lil' helper
Tux's lil' helper


Joined: 30 Sep 2002
Posts: 141

PostPosted: Thu Sep 21, 2006 10:04 pm    Post subject: bash: variable zeilenweise in file schreiben[solved] Reply with quote

Hallo ihr

Ich habe innerhalb eines shell-scripts eine Variable namens $online die so aussieht:

Code:
aaaaa:111 bbbbb:222


Die Trennung soll am space stattfinden.
Jetzt möchte ich gerne in einem Rutsch am Ende des Scripts $online in ein File schreiben, aber zeilenweise.
Ich denke mal in Verbindung mit EOF und awk oder so in der Art geht das bestimmt.

Code:

cat > $state_file <<EOF
`echo $online .....`
EOF


Bin nicht so der shell-Freak. :oops:
Kann mir mal jemand einen Anstoß geben?

Danke im Voraus
Gruß, Martini


Last edited by Martini on Fri Sep 22, 2006 9:17 am; edited 1 time in total
Back to top
View user's profile Send private message
psyqil
Advocate
Advocate


Joined: 26 May 2003
Posts: 2767

PostPosted: Thu Sep 21, 2006 10:53 pm    Post subject: Reply with quote

Code:
echo $online|cut -d " " -f 1 > online.tst
echo $online|cut -d " " -f 2 >> online.tst
Reicht das?
Back to top
View user's profile Send private message
Martini
Tux's lil' helper
Tux's lil' helper


Joined: 30 Sep 2002
Posts: 141

PostPosted: Fri Sep 22, 2006 8:16 am    Post subject: Reply with quote

Hallo psyqil

Danke erstmal. Reicht leider so nicht.
Der Inhalt der Variable wird vorher im script zusammengebaut und kann sich ständig ändern.
Könnte z.B. auch so aussehen:
Code:
aaaaa:111 bbbbb:222 ccccc:3333 dddddd:444

Der Zusammenbau der Variable kann einige Sekunden dauern. Deswegen möchte ich am Ende des Scripts
alles in einem Rutsch in ein File schreiben.
Achso, man könnte das ja in ne for-Schleife bauen. Wenns nicht anders geht, probier ichs mal so.
Dachte nur man könne das mit EOF irgendwie machen.

Danke
Martin
Back to top
View user's profile Send private message
psyqil
Advocate
Advocate


Joined: 26 May 2003
Posts: 2767

PostPosted: Fri Sep 22, 2006 8:37 am    Post subject: Reply with quote

Code:
echo $ONLINE|sed "s/ /\n/g" > file
Besser? :P
Back to top
View user's profile Send private message
Vaarsuvius
Guru
Guru


Joined: 02 Dec 2004
Posts: 345

PostPosted: Fri Sep 22, 2006 8:54 am    Post subject: Reply with quote

psyqil wrote:
Code:
echo $ONLINE|sed "s/ /\n/g" > file
Besser? :P

oder
Code:
for i in $online; do `echo $i >> file`; done
Back to top
View user's profile Send private message
Martini
Tux's lil' helper
Tux's lil' helper


Joined: 30 Sep 2002
Posts: 141

PostPosted: Fri Sep 22, 2006 9:13 am    Post subject: Reply with quote

Dankeschön :P
Sowas hab ich gesucht. :)

Gruß
Martin
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum