2014-09-11 7 views
1

J'ai un fichier qui contient des données comme ceci:Essayer d'écrire script shell sous Linux

1;2;3 
4;5;6 
7;8;9 
.... 
n 

où n est un numer aléatoire de lignes. J'essaie d'obtenir à partir de ce fichier quelque chose comme ceci:

command_1_command_2_command_3 
command_4_command_5_command_6 
.... 
n 

Toutes les suggestions comment puis-je réaliser cela?

+1

Attend facile à faire avec 'awk'. Essayez-le et publiez ce que vous avez si vous n'arrivez pas à le faire fonctionner. – Barmar

+0

Le fichier contient-il vraiment des puces au début de chaque ligne? – Barmar

+0

Bien sûr que non. J'ai eu des problèmes avec le formatage du texte - maintenant c'est correct :) – NRG

Répondre

3

essayer,

awk 'BEGIN {FS=";"}; {$1="command_"$1;$2="command_"$2;$3="command_"$3;print $1"_"$2"_"$3}' stacko.txt 

[email protected]:~$ cat stacko.txt 
1;2;3 
4;5;6 
7;8;9 
[email protected]:~$ awk 'BEGIN {FS=";"}; {$1="command_"$1;$2="command_"$2;$3="command_"$3;print $1"_"$2"_"$3}' stacko.txt 
command_1_command_2_command_3 
command_4_command_5_command_6 
command_7_command_8_command_9 
[email protected]:~$ 
+0

Fonctionne bien! Je vous remercie! – NRG