2010-11-17 10 views
0

Existe-t-il un moyen d'avoir awk pas imprimer une colonne de largeur fixe?chaîne d'impression awk sans formatage à largeur fixe?

Par exemple:

"9", "TAYLOR TOWER, JACOB B. " 
"9", "UNIVERSITY HOSPITALS-EAST" 
"AR", "SCHOTTENSTEIN CENTER  " 
"B1", "NEWARK RESIDENCE HALL " 
"B2", "NEWARK RESIDENCE HALL " 
"CC", "OHIO STADIUM    " 
"D1", "TELECOM NETWORK CENTER " 
"DC", "SCHOTTENSTEIN CENTER  " 
"EN", "SCHOTTENSTEIN CENTER  " 
"GR", "UNIVERSITY HOSPITALS-EAST" 
"LL", "RANEY COMMONS, 2ND LT. AL" 
"MZ", "PHYSICS RESEARCH  " 
"MZ", "SCHOTTENSTEIN CENTER  " 
"NS", "STARLING LOVING HALL " 
"P1", "OHIO STADIUM    " 
"P2", "OHIO STADIUM    " 
"P3", "OHIO STADIUM    " 

Je veux que ce soit imprimé:

"9", "TAYLOR TOWER, JACOB B." 
"9", "UNIVERSITY HOSPITALS-EAST" 
"AR", "SCHOTTENSTEIN CENTER" 
"B1", "NEWARK RESIDENCE HALL" 
"B2", "NEWARK RESIDENCE HALL" 
"CC", "OHIO STADIUM" 
"D1", "TELECOM NETWORK CENTER" 
"DC", "SCHOTTENSTEIN CENTER" 
"EN", "SCHOTTENSTEIN CENTER" 
"GR", "UNIVERSITY HOSPITALS-EAST" 
"LL", "RANEY COMMONS, 2ND LT. AL" 
"MZ", "PHYSICS RESEARCH" 
"MZ", "SCHOTTENSTEIN CENTER" 
"NS", "STARLING LOVING HALL" 
"P1", "OHIO STADIUM" 
"P2", "OHIO STADIUM" 
"P3", "OHIO STADIUM" 

Notez que le deuxième champ dans ce texte n'a pas d'espace à l'intérieur des guillemets. Est-ce possible?

Répondre

1

Dans AWK (gawk/nawk)

{sub(/[ ]*\"$/, "\"");print} 
1

j'utiliser sed au lieu de awk, bien que vous pouvez faire gsub awk si vous devez:

sed -e 's/ *"$/"/' 

Signification « tourner un ou plusieurs espaces, suivi par citation à la fin de la ligne en juste citation "