Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Trennzeichen in awk

Empfohlene Antworten

Veröffentlicht

hallo,

kann ich in awk ein ' oder " als trennzeichen angeben ?

angenommen ich habe folgende datei : test.dat


müller;meier;schmidt

anton;berta;theodor

er;sie;es

dann liefert mir :
 

gawk ' BEGIN {FS=";"} {print $1 "\t" $2 "\t" $3}' test.dat

folgende Ausgabe :
 

müller    meier    schmidt

anton     berta    theodor

er        sie      es

Wenn die Datei test.dat durch Hochkomma bzw. Anführungsstriche getrennt ist und ich das jeweilige

zeichen als trennzeichen angebe (z.b. FS=" ' ") erwartet gawk weitere eingaben, nachdem ich den

befehl ausführen möchte.

wie kann ich denn ein ' bzw. " als trennzeichen angeben ?

danke schon einmal im voraus

mfg

mike

suppi :-))

mike@linux:~/diff> less test.dat

a"b"c

d"e"f

g"h"i

mike@linux:~/diff> gawk 'BEGIN {FS="\""} {print $1 "\t" $2 "\t" $3}' test.dat

a       b       c

d       e       f

g       h       i

mike@linux:~/diff>

Mit dem Hochkomma funktioniert es allerdings noch nicht

mike@linux:~/diff> less test.dat

a'b'c

d'e'f

g'h'i

mike@linux:~/diff> gawk 'BEGIN {FS="\'"} {print $1 "\t" $2 "\t" $3}' test.dat

>

mike@linux:~/diff>

in der vorletzten Zeile breche ich mit strg+c ab.

ich kann den dateinamen test.dat auch nicht mit der tabulatortaste vervollständigen.

ja, dein kommando ist nicht vollständig.

da du das ' nicht mit dem " maskieren kannst weil es "mächtiger" ist.

deshalb hast du 3 ' in deinem befehl, dann denkt er es fehlt zum schluss noch ein ' und du wirst selbst nach enterdrücken mit dem > aufgefordert deinen befehl zu vervollständigen.

versuch mal


gawk `BEGIN {FS=`\'`} {print $1 "\t" $2 "\t" $3}` test.dat

habs nicht getestet, aber das scheint mir am plausibelsten ...

geht btw auch mit

awk -F\' ...

funktioniert mit awk wunderbar...danke :-))

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.