Codice: Seleziona tutto
cat hapmap3_r2_b36_fwd.ASW.qc.poly.ped | sed -ir 's/^(([^ \t]* ){5})'"$toremove"' (.*)$/\1'"$toinsert"' \2/'
Codice: Seleziona tutto
sed: -e expression #1, char 36: invalid reference \2 on `s' command's RHS
Codice: Seleziona tutto
cat hapmap3_r2_b36_fwd.ASW.qc.poly.ped | sed -ir 's/^(([^ \t]* ){5})'"$toremove"' (.*)$/\1'"$toinsert"' \2/'
Codice: Seleziona tutto
sed: -e expression #1, char 36: invalid reference \2 on `s' command's RHS


No si passa il file direttamente al comando sed, alla fine del comando.cloudany [url=http://forum.ubuntu-it.org/viewtopic.php?p=4603130#p4603130][img]http://forum.ubuntu-it.org/images/icons/icona-cita.gif[/img][/url] ha scritto:Al posto di ECHO per leggere un file uso cat giusto?

Codice: Seleziona tutto
sed -ir 's/^(([^ \t]* ){5})'"$toremove"' (.*)$/\1'"$toinsert"' \2/' hapmap3_r2_b36_fwd.ASW.qc.poly.ped

Codice: Seleziona tutto
#! /bin/bash
toremove=-9
toinsert=ASW
sed -ir 's/^(([^ \t]* ){5})'"$toremove"' (.*)$/\1'"$toinsert"' \2/'

Codice: Seleziona tutto
#! /bin/bash
toremove=-9
toinsert=ASW
sed -ir 's/^(([^ \t]* ){5})'"$toremove"' (.*)$/\1'"$toinsert"' \2/' hapmap3_r2_b36_fwd.ASW.qc.poly.pedCodice: Seleziona tutto
sed: -e expression #1, char 36: invalid reference \2 on `s' command's RHS

Codice: Seleziona tutto
sed --versionCodice: Seleziona tutto
sed (GNU sed) 4.2.2
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo Bonzini.
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed@gnu.org>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
Codice: Seleziona tutto
#!/bin/bash
toremove='-9'
toinsert='ASW'
sed -r 's/^(([^ \t]* ){5})'"$toremove"' (.*)$/\1'"$toinsert"' \2/' hapmap3_r2_b36_fwd.ASW.qc.poly.ped
Codice: Seleziona tutto
8-) cat hapmap3_r2_b36_fwd.ASW.qc.poly.ped
2427 NA19919 NA19908 NA19909 1 -9 c7_1 c8_1 c9_1 c10_1
2528 NA19920 NA19909 NA19910 1 -9 c7_2 c8_2 c9_2 c10_2
2529 NA19921 NA19910 NA19911 1 foo c7_3 c8_3 c9_3 c10_3
2530 NA19922 NA19911 NA19912 1 foo c7_4 c8_4 c9_4 c10_4
Codice: Seleziona tutto
8-) awk -F $'\t' 'BEGIN {OFS = FS} { if ($6 == "-9") $6="ASW"; print > "parte1.txt" }' <(cut -f1-6 hapmap3_r2_b36_fwd.ASW.qc.poly.ped)
Codice: Seleziona tutto
8-) cat parte1.txt
2427 NA19919 NA19908 NA19909 1 ASW
2528 NA19920 NA19909 NA19910 1 ASW
2529 NA19921 NA19910 NA19911 1 foo
2530 NA19922 NA19911 NA19912 1 foo
Codice: Seleziona tutto
8-) cut -f7- hapmap3_r2_b36_fwd.ASW.qc.poly.ped > parte2.txtCodice: Seleziona tutto
8-) cat parte2.txt
c7_1 c8_1 c9_1 c10_1
c7_2 c8_2 c9_2 c10_2
c7_3 c8_3 c9_3 c10_3
c7_4 c8_4 c9_4 c10_4
Codice: Seleziona tutto
8-) paste parte1.txt parte2.txt > risultato.txtCodice: Seleziona tutto
8-) cat risultato.txt
2427 NA19919 NA19908 NA19909 1 ASW c7_1 c8_1 c9_1 c10_1
2528 NA19920 NA19909 NA19910 1 ASW c7_2 c8_2 c9_2 c10_2
2529 NA19921 NA19910 NA19911 1 foo c7_3 c8_3 c9_3 c10_3
2530 NA19922 NA19911 NA19912 1 foo c7_4 c8_4 c9_4 c10_4


Ho provato su un file con molte meno colonne, e non ha dato problemi, quindi presumo sia appunto il numero esagerato di colonne a dar problemi, anche Libreoffice storceva il naso davanti a quel file.vaeVictis [url=http://forum.ubuntu-it.org/viewtopic.php?p=4603604#p4603604][img]http://forum.ubuntu-it.org/images/icons/icona-cita.gif[/img][/url] ha scritto:"Dovresti" anche capire come mai ti dava errore l'altro comando.
Visualizzano questa sezione: 0 utenti iscritti e 4 ospiti