Johanni
November 25, 2011, 10:34am
1
hey guys,
I'm going to make a sed file out of a list of words
words.dat:
802.11a
802.11b
802.11g
802.11n
my command:
awk '{print $0,"/spEC/g"}' words.dat |
awk '{print "s/"$0}'
current output
s/802.11a /spEC/g
s/802.11b /spEC/g
s/802.11g /spEC/g
s/802.11n /spEC/g
s/Player /spEC/g
s/Server /spEC/g
desired output
s/802.11a/spEC/g
s/802.11b/spEC/g
s/802.11g/spEC/g
s/802.11n/spEC/g
s/Player/spEC/g
s/Server/spEC/g
I don't want to have to have those extra spaces.
could you please help me with that.
tnx
sed 's#^#s/#;s#$#/spEC/g#' myFile
awk '{print "s/" $0 "/spEC/g"} myFile
CarloM
November 25, 2011, 11:34am
3
Just remove the comma:
# awk '{print $0"/spEC/g"}' words.dat
802.11a/spEC/g
802.11b/spEC/g
802.11g/spEC/g
802.11n/spEC/g
Also, you don't need 2 awk commands:
# awk '{print "s/"$0"/spEC/g"}' words.dat
s/802.11a/spEC/g
s/802.11b/spEC/g
s/802.11g/spEC/g
s/802.11n/spEC/g
Johanni
November 25, 2011, 12:26pm
4
thanks a lot it worked perfect
but there is one small problem, in the word.dat file I have some words like:
JPEG / JPG
TIFF
PNG
BMP
GIF
DivX
Xvid
MPEG1
MPEG2
MPEG4
WMV
H.263
3GP/3GPP
you see that some of them have "/" in the middle, so the problem is the output sed file like this would not work, because it has extra "/"
So what structure you suggest for the sed file:
s/JPEG / JPG/spEC/g
s/TIFF/spEC/g
s/PNG/spEC/g
s/BMP/spEC/g
s/GIF/spEC/g
s/DivX/spEC/g
s/Xvid/spEC/g
s/MPEG1/spEC/g
s/MPEG2/spEC/g
s/MPEG4/spEC/g
s/WMV/spEC/g
s/H.263/spEC/g
s/3GP/3GPP/spEC/g
for example "3GP/3GPP" has extra "/"
CarloM
November 25, 2011, 12:29pm
5
The separator for sed does not have to be '/' - you can equally use '#' or whatever.
awk '{print "s#"$0"#spEC#g"}' words.dat
I don't quite follow the logic...
Why are you creating a sed file with awk/sed, while you can do the actual substitution with awk directly?