OT, blowing off steam

C

ccc31807

For the past two days, I've been engaged in moving a CGI application
from Windows to Linux, and boy, have I gotten an education! I would
have undertaken the project if I had know how frustrating it would be,
but I would have been a lot less enthusiastic going in.

I have spend most of my time (so far) struggling with data input to
MySQL, both schema and data. After hours of blind groping, I figured
out the intricacies of mysqlimport, LOAD DATA FILE, and mysql -e
between different versions and different OSes. Thank God for Perl --
writing simple scripts to munge the input files to read them into
MySQL was both easy and fun, and effective.

Now, I'm dealing with the differences between Perl versions, the one
on the Linux server is a lot older than the Windows server, but that's
straightforward. If something doesn't work, it's easy enough to fix by
hand -- unless someone knows of a library that translates from one
version to another.

The point of this post, other than just to blow off steam and take a
break, is to share a couple of vi tips that I discovered. These have
proven useful to me, and may to others, and besides, if I forget them
I can simply google c.l.p.m.

First, how to insert a non-printable character in a (vim) regular
expression? Let's say you want to replace form feeds (^@) with
nothing. You can see the codes for characters by giving the
command :digraphs, and then insert the character in the regular
expression by doing Cntl-k, two letter code.

Second, how to convert a simple, ASCII text file from Windows to
Linux? The problem was an unfathomable premature end of script headers
error that I was at my wit's end to fix. In vi (vim), you give the
command :set fileformat:unix, and presto, chango, the premature end of
script headers error disappears!

Yeah, I know this is OT, but I thought this might help someone else,
and I needed to do something to relax anyway.

CC.
 
J

Jürgen Exner

ccc31807 said:
Now, I'm dealing with the differences between Perl versions, the one
on the Linux server is a lot older than the Windows server,

Then why don't you upgrade the Linux version? Or install your own
version?
First, how to insert a non-printable character in a (vim) regular
expression? Let's say you want to replace form feeds (^@) with
nothing.

Doesn't \f work?
Second, how to convert a simple, ASCII text file from Windows to
Linux?

man dos2unix


jue
 
K

Keith Thompson

ccc31807 said:
First, how to insert a non-printable character in a (vim) regular
expression? Let's say you want to replace form feeds (^@) with
nothing. You can see the codes for characters by giving the
command :digraphs, and then insert the character in the regular
expression by doing Cntl-k, two letter code.
[...]

^@ is the null character, not form feed.
 
C

ccc31807

^@ is the null character, not form feed.

Typing control-k, LF in vim inserts ^@. Typing control-k, NU inserts
^U.

Look at the symbols using the :digraphs command.

CC.
 
C

ccc31807


I'm using gVim on Windows XP at work, and I'm not at that machine so I
can't check it now. I could have made a mistake, and if so I'll admit
it. But I did check it twice, and it's LF = ^@ and NU = ^U.

Like I said, if I made a mistake, I'll let you know on Monday.

CC.
 
S

sreservoir

I'm using gVim on Windows XP at work, and I'm not at that machine so I
can't check it now. I could have made a mistake, and if so I'll admit
it. But I did check it twice, and it's LF = ^@ and NU = ^U.

Like I said, if I made a mistake, I'll let you know on Monday.

it's probably a system inconsistency.

my output:

NU ^@ 10 SH ^A 1 SX ^B 2 EX ^C 3 ET ^D 4 EQ ^E 5
AK ^F 6 BL ^G 7 BS ^H 8 HT ^I 9 LF ^@ 10 VT ^K 11
FF ^L 12 CR ^M 13 SO ^N 14 SI ^O 15 DL ^P 16 D1 ^Q 17
D2 ^R 18 D3 ^S 19 D4 ^T 20 NK ^U 21 SY ^V 22 EB ^W 23
CN ^X 24 EM ^Y 25 SB ^Z 26 EC ^[ 27 FS ^\ 28 GS ^] 29
RS ^^ 30 US ^_ 31 SP 32 Nb # 35 DO $ 36 At @ 64
<( [ 91 // \ 92 )> ] 93 '> ^ 94 '! ` 96 (! { 123
!! | 124 !) } 125 '? ~ 126 DT ^? 127 PA ~@ 128 HO ~A 129
BH ~B 130 NH ~C 131 IN ~D 132 NL ~E 133 SA ~F 134 ES ~G 135
HS ~H 136 HJ ~I 137 VS ~J 138 PD ~K 139 PU ~L 140 RI ~M 141
S2 ~N 142 S3 ~O 143 DC ~P 144 P1 ~Q 145 P2 ~R 146 TS ~S 147
CC ~T 148 MW ~U 149 SG ~V 150 EG ~W 151 SS ~X 152 GC ~Y 153
SC ~Z 154 CI ~[ 155 ST ~\ 156 OC ~] 157 PM ~^ 158 AC ~_ 159
NS | 160 !I ¡ 161 Ct ¢ 162 Pd £ 163 Cu ¤ 164 Ye ¥ 165
BB ¦ 166 SE § 167 ': ¨ 168 Co © 169 -a ª 170 << « 171
NO ¬ 172 -- ­ 173 Rg ® 174 'm ¯ 175 DG ° 176 +- ± 177
2S ² 178 3S ³ 179 '' ´ 180 My µ 181 PI ¶ 182 .M · 183
', ¸ 184 1S ¹ 185 -o º 186 >> » 187 14 ¼ 188 12 ½ 189
34 ¾ 190 ?I ¿ 191 A! À 192 A' Á 193 A> Â 194 A? Ã 195
A: Ä 196 AA Å 197 AE Æ 198 C, Ç 199 E! È 200 E' É 201
E> Ê 202 E: Ë 203 I! Ì 204 I' Í 205 I> Î 206 I: Ï 207
D- Ð 208 N? Ñ 209 O! Ò 210 O' Ó 211 O> Ô 212 O? Õ 213
O: Ö 214 *X × 215 O/ Ø 216 U! Ù 217 U' Ú 218 U> Û 219
U: Ü 220 Y' Ý 221 TH Þ 222 ss ß 223 a! à 224 a' á 225
a> â 226 a? ã 227 a: ä 228 aa å 229 ae æ 230 c, ç 231
e! è 232 e' é 233 e> ê 234 e: ë 235 i! ì 236 i' í 237
i> î 238 i: ï 239 d- ð 240 n? ñ 241 o! ò 242 o' ó 243
o> ô 244 o? õ 245 o: ö 246 -: ÷ 247 o/ ø 248 u! ù 249
u' ú 250 u> û 251 u: ü 252 y' ý 253 th þ 254 y: ÿ 255
~! ¡ 161 c| ¢ 162 $$ £ 163 ox ¤ 164 Y- ¥ 165 || ¦ 166
cO © 169 -, ¬ 172 -= ¯ 175 ~o ° 176 22 ² 178 33 ³ 179
pp ¶ 182 ~. · 183 11 ¹ 185 ~? ¿ 191 A` À 192 A^ Â 194
A~ Ã 195 A" Ä 196 A@ Å 197 E` È 200 E^ Ê 202 E" Ë 203
I` Ì 204 I^ Î 206 I" Ï 207 N~ Ñ 209 O` Ò 210 O^ Ô 212
O~ Õ 213 /\ × 215 U` Ù 217 U^ Û 219 Ip Þ 222 a` à 224
a^ â 226 a~ ã 227 a" ä 228 a@ å 229 e` è 232 e^ ê 234
e" ë 235 i` ì 236 i^ î 238 n~ ñ 241 o` ò 242 o^ ô 244
o~ õ 245 u` ù 249 u^ û 251 y" ÿ 255


so yes, LF does produce ^@, but I only have NK for ^U.
 
R

RedGrittyBrick

I'm using gVim on Windows XP at work, and I'm not at that machine so I
can't check it now. I could have made a mistake, and if so I'll admit
it. But I did check it twice, and it's LF = ^@ and NU = ^U.

Like I said, if I made a mistake, I'll let you know on Monday.

In vim, insert your character using Control+K L F then position the
cusror over the caret (^) and press ga then press g8. Finally write the
text to a file and look at a hex dump

I inserted aaa control+K L F bbb
ga said 0x00
g8 said 0x0a

On Unix, hd gave
0000 61 61 61 00 62 62 62 0a aaa.bbb.

On Windows, od -t x1 gave
0000000 61 61 61 00 62 62 62 0d 0a
0000011

I conclude that inserting a linefeed into the middle of a line in a text
file is a confusing thing to do in a text editor.

I don't understand how Vim is interpreting these actions or whether it's
display makes sense in context.

I think Keith's right to interpret ^@ as null. ^J would be LF.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top