Erfordernis
Col1 , Col2 , Col3 , Col4
1 , a:/b/c/abc.txt , f:/b/c/abc1.txt , a:/b/c/abc6.txt
2 , b:/bd/a/s/3/d/mon.dat , g:/b/c/abc 2.txt, b:/b/c/ab7.txt
3 , c:/j/h/4/u/y/d/m/ttt.dat, h:/b/c/abc 3.txt, c:/b/c/abc 8.txt
4 , c:/j/h/4/test1.msg , i:/b/c/abc4.txt , d:/b/c/abc 9.txt
5 , d:/iasa/dda/dia/yyy.dat , j:/b/c/abc5.txt , e:/b/c/abc 10.txt
Erwartet O/P
Col1 , Col2 , Col3 , Col4
1 , abc.txt , abc1.txt , abc6.txt
2 , mon.dat , abc2.txt , abc7.txt
3 , ttt.dat , abc3.txt , abc8.txt
4 , test1.msg , abc4.txt , abc9.txt
5 , yyy.dat , abc5.txt , abc10.txt
Antwort1
Da ich kein System in der Raumaufteilung erkennen konnte, habe ich einfach eine Formatierung erraten. Passen Sie diese gerne Ihrem Geschmack an.
awk -F, '{gsub (/ |\r/, ""); printf "%-4s ", $1; for (i=2; i<=NF; i++) {n=split($i, T, "/"); printf ", %-10s ", T[n]} printf RS}' OFS=, file
Col1 , Col2 , Col3 , Col4
1 , abc.txt , abc1.txt , abc6.txt
2 , mon.dat , abc2.txt , ab7.txt
3 , ttt.dat , abc3.txt , abc8.txt
4 , test1.msg , abc4.txt , abc9.txt
5 , yyy.dat , abc5.txt , abc10.txt
Antwort2
Verwenden von sed
und column
:
$ sed 's/ //g; s/,[^,]*\//,/g; s/,/ , /g' file | column -t
Col1 , Col2 , Col3 , Col4
1 , abc.txt , abc1.txt , abc6.txt
2 , mon.dat , abc2.txt , ab7.txt
3 , ttt.dat , abc3.txt , abc8.txt
4 , test1.msg , abc4.txt , abc9.txt
5 , yyy.dat , abc5.txt , abc10.txt
- Ersetzen Sie alle Leerzeichen durch eine leere Zeichenfolge.
- Ersetzen Sie alle
,
gefolgt von Nicht-,
Zeichen, gefolgt von/
durch ein,
- ersetzen Sie alle
,
durch,
- Drucken Sie die Ausgabe als Tabelle mit
column