2/17 This *has* to exist: I'm working w/ a text file that uses ascii #2
for record separators and ascii #1 for field separators. Is there
a utility that will print out these ascii values for me, so I can
(for example) use them with command line awk and perl scripts? Ex:
fs=`atoi 1`
perl -pi e's/(.*)$fs(.*)/$1$fsfoobar/g' myfile.txt
Also, what would the actual perl syntax be for what I'm trying to
do with the above command? Platform is OS X. TIA
\_ perl -002 -a -F'\001' -lpi -e '$_="$F[0]foobar"' myfile.txt
OK, this sets in the input record separator to #2 (instead of
newline), sets the field separator to #1, strips the \002 from the
input and readds it on output (-l) and autosplits into @F on \1
--dbushong
\_ What about a function that just prints an ascii code -
printf("%c", atoi(argv[0]));
would be fine, it just seems ridiculous that this doesn't
already exist.
\_ In most shells, you can press ^V before a keystroke and have
that keystroke inserted literally, without being interpreted
by the shell. Thus, ^V^A would produce a literal ^A (ASCII
code 0x01), and ^V^B would produce a literal ^B (ASCII 0x02).
Alternatively, try fs=`echo -ne '\001'`. -gm
\_ Ah, that works very well, thank you. I also
discovered the perl function chr, which takes an int
and returns the associated ascii character.
\_ I think you meant argv[1], there, buddy. Anyway, it's
trivial, so why don't you write it?
\_ You're correct, and yes it's trivial, but so is the
command "yes" which repeatedly prints out "y" forever.
The thing is, I need to have other people run this
script for me, and I don't want to waste their time
with "ok, now run gcc -o asciify asciify.c" if asciify
already exists. |