I use a csh/tcsh-script which asks questions about specific
files/directories. These questions should be answered by input from the
keyboard. But sometimes it happens that press a special key (eg. arrows,
Ins, Del, ...) which results in a input string that contains
non-printable characters. I wish to use AWK to remove these characters
or to ask the questions and read the answers from the keyboard.
I have three questions that I think can solve my problem:
Can I use Awk to remove these non-printable characters (ASCII 0 - 31)?
Can I use Awk to read input from the keyboard immediately?
Can I use Awk to read input from the keyboard AND a input file at the
same time (the input file may come from stdin)?
Regards,
/Göran Wiréen,
Combitech Software, Sweden
> I use a csh/tcsh-script which asks questions about specific
> files/directories. These questions should be answered by input from
> the keyboard. But sometimes it happens that press a special key
> (eg. arrows, Ins, Del, ...) which results in a input string that
> contains non-printable characters. I wish to use AWK to remove these
> characters. Can I use Awk to remove these non-printable characters
> (ASCII 0 - 31)?
/[\001-\007\013\016-\037]/{gsub(/[\001-\007\013\016-\037]/,"")}
However, note that the VT100 arrow and/or numerical keypad keys
generate multicharacter sequences, of which only the first is a
control character (e.g. ESC-"["-"O"-"A" or whatever).
--
Henry Churchyard || "...equal to 2800 pounds, 19 shillings, and elevenpence
three farthings, as nearly as can be expressed in English money, the Aphanian
currency being a complex decimal coinage which would take too long to explain"
- Tom Hood, _Petsetilla's Posy_ (1870) http://uts.cc.utexas.edu/~churchh
On Tue, 21 Apr 1998 09:28:49 +0200, Göran Wiréen
<Goran....@software.combitech.se> wrote:
> I use a csh/tcsh-script which asks questions about specific
> files/directories. These questions should be answered by input from the
You should read the answers to shell variables. I don't thing you should
use awk in the task you described.
I'd use read built-in command in bash. If it really is that bad that csh
has no builtin for reading from console, you could use this
set variable=`head -1`
and then "echo $variable" or whatever.
(Any csh fans to correct me?)
> Can I use Awk to remove these non-printable characters (ASCII 0 - 31)?
You probably can, but you should use one of these commands:
tr -d '[:cntrl:]'
tr -cd '[:print:]'
The rest is only as BTW:
> Can I use Awk to read input from the keyboard immediately?
> Can I use Awk to read input from the keyboard AND a input file at the
> same time (the input file may come from stdin)?
If stdin is tty, awk gets everything from terminal.
If in pipe, you can read from tty by on eof this:
getline <"/dev/tty"
getline var <"/dev/tty"
Yours, Stepan
In csh, you can read an input line from the console as follows:
set line = ${<}
Barbara Vaughan