2016-03-30 10 views
0

Ich mache ein Tutorial in der Befehlszeile. In einer der Übungen muss ich eine sonnet und echo in eine neue Datei kopieren. Problem ist, dass die neuen Zeilen nicht in der neuen Datei vorhanden sind, in der Tat, wenn ich die Datei cat, jeder Vers an den vorherigen angehängt ist.Kopieren, Einfügen und Echo in txt-Datei mit Zeilenumbrüchen

Muss ich am Ende jeder Zeile manuell "\n" hinzufügen? Ich hoffe, es gibt einen besseren Weg

UPDATE (weil das, was, wenn es 1000 Zeilen sind?): Dies ist, was ich bis jetzt

Erste getan haben kopiere ich das Sonett von here. Dann füge ich es im Terminal diesen Befehl zu schreiben:

~$ echo "FRom faireſt creatures we deſire increaſe, That thereby beauties Roſe might neuer die, But as the riper ſhould by time deceaſe, His tender heire might beare his memory: But thou contracted to thine owne bright eyes, Feed’ſt thy lights flame with ſelfe ſubſtantiall fewell, Making a famine where aboundance lies, Thy ſelfe thy foe,to thy ſweet ſelfe too cruell: Thou that art now the worlds freſh ornament, And only herauld to the gaudy ſpring, Within thine owne bud burieſt thy content, And tender chorle makſt waſt in niggarding: Pitty the world,or elſe this glutton be, To eate the worlds due,by the graue and thee." > sonnet.txt 

schließlich prüfe ich den Inhalt:

cat sonnet.txt 

aber ich bekomme:

FRom faireſt creatures we deſire increaſe, That thereby beauties Roſe might neuer die, But as the riper ſhould by time deceaſe, His tender heire might beare his memory: But thou contracted to thine owne bright eyes, Feed’ſt thy lights flame with ſelfe ſubſtantiall fewell, Making a famine where aboundance lies, Thy ſelfe thy foe,to thy ſweet ſelfe too cruell: Thou that art now the worlds freſh ornament, And only herauld to the gaudy ſpring, Within thine owne bud burieſt thy content, And tender chorle makſt waſt in niggarding: Pitty the world,or elſe this glutton be, To eate the worlds due,by the graue and thee. 
+0

Haben _copy-paste ein Sonnet_ nicht erhalten. Ist _sonnet_ eine Zeichendatei oder etwas anderes? – Mahendra

+0

Welchen Befehl verwenden Sie, um dies zu tun? 'echo [einfügen]> Datei'? Enthält der eingefügte Inhalt Leerzeilen zwischen jedem Vers? –

+0

@Mahendra, Tut mir leid, ich habe vergessen, einen Link – Pigna

Antwort

0

dies für Sonette funktioniert :)

$ sonnet="Shall I compare thee to a summer.s day? 
> Thou art more lovely and more temperate. 
> Rough winds do shake the darling buds of May," 

$ echo "$sonnet" 
Shall I compare thee to a summer.s day? 
Thou art more lovely and more temperate. 
Rough winds do shake the darling buds of May, 

Ich denke, dass Sie die d fehlen doppelte Anführungszeichen

$ echo $sonnet 
Shall I compare thee to a summer.s day? Thou art more lovely and more temperate. Rough winds do shake the darling buds of May, 
+0

Es funktioniert nicht. Bitte sieh dir den Link an (ich habe es vergessen). Versuchen Sie, es zu kopieren und einzufügen und dann in eine TXT-Datei zu übertragen. Wie behalten Sie die Zeilenumbrüche? – Pigna

+0

spielt keine Rolle, welches Sonett/welchen Text Sie verwenden. Hast du auf die Zitate geachtet? Sowohl beim Definieren der Variablen als auch beim Zurückspechen. Bitte posten Sie genaue Befehle, die Sie im ursprünglichen Beitrag verwenden. Vielleicht tust du etwas anderes ... – karakfa

+0

1. markiere das Sonett auf der Seite, 2. ctrl-c, 3. tippe das Terminal "echo" ein, 4. tippe "$ [paste]", 5. tippe " > sonnet.txt ", 6. Klicken Sie auf Enter – Pigna