Results 1 to 4 of 4
Hello,
I've file, with following content
Code:
sys true hide Basesystem
desktop true show Xserver, Gnome, Kde, ...
office true show Openoffice, TeX, Acroread, Groupwise, ...
science false show gnuplot, ...
- 04-12-2010 #1Just Joined!
- Join Date
- Apr 2010
- Posts
- 2
subsitute parts from a file (information in a string)
Hello,
I've file, with following content
Then I've string in a fileCode:sys true hide Basesystem desktop true show Xserver, Gnome, Kde, ... office true show Openoffice, TeX, Acroread, Groupwise, ... science false show gnuplot, xmgrace, octave, R, ...
"desktop" "science"
With the information of that file I want change the previous file, in each line where the key word is in the string I want "true" in the second column, otherwise there should bei false...
in this example
(the seperator is tab ...)Code:sys false hide Basesystem desktop true show Xserver, Gnome office false show openoffice, TeX, science true show xmgrace, octave, R, ...
How can I do this ( in a nice way)?
Ansir
- 04-14-2010 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try:
Code:awk 'NR==FNR{p=$1;s=$2;next}$1==p{$2=s}1' OFS="\t" file_with_string mainfile
- 04-14-2010 #3Just Joined!
- Join Date
- Apr 2010
- Posts
- 2
thank your for the answer, but i think it doesn't work for me (or my question was not clear enough)
mainfile
then I have a file dat.tmpCode:sys true hide Basesystem desktop false show Xserver, Gnome, Kde, ... office true show Openoffice, Groupwise, ... science false show gnuplot, xmgrace, R, ..
nothing happensCode:"desktop" "office"
when I remove the '"' an try
awk 'NR==FNR{p=$1;s=$2;next}$1==p{$2=s}1' dat.tmp mainfile
In the line of desktop there appears "office"....Code:sys true hide Basesystem desktop office show Xserver, Gnome, Kde, ... office true show Openoffice, Groupwise, ... science false show gnuplot, xmgrace, R, ..
but I want the following
mainfile
the second column should be "true" when one can find a element of the string in it, otherwise the second column should bei falseCode:sys false hide Basesystem desktop true show Xserver, Gnome, Kde, ... office true show Openoffice, Groupwise, ... science false show gnuplot, xmgrace, R, ..
Ansir
- 04-14-2010 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
I'm sorry, misread something, try this one:
Code:awk ' NR==FNR{ gsub("\"","") p=$1;s=$2 next } $1==p || $1==s{$2="true"} 1' OFS="\t" dat.temp mainfile


Reply With Quote