Vi special character

When editing a file, vi displays a special character as ^L. Can you tell me the escaped character to be used in awk? And can that escaped character be used in a regexp in both sed and awk?

That is a form feed, octal 014.

How to embed this in other things can vary, but you can try \014 inside strings in awk. Whether sed allows this depends on your version of sed.

1 Like

Use printf inside sed to create a form feed and remove it:

sed 's/'"$(printf '\014')"'$//g' inputfile > outputfile
1 Like

There's no need to resort to that level of inefficient and complicated indirection. In most terminals, one can simply type control-v control-x to generate the character denoted by ^x, where x is whatever symbol is displayed.

sed 's/^L//g'

where ^L is the result of control-v control-l.

stty usually defines ^v as the quoting character. When used, the terminal subsytem will treat the next character literally. You can use this to produce non-graphic characters which are usually displayed with that caret notation, ^@, ^L, etc. You can also use it to bypass tab completion and insert a literal tab.

Regards,
Alister

2 Likes

In addition to what has already been said, you can also use \f to represent the form-feed character in awk's strings and regular expressions, in printf's format strings, and in some (but not all) versions of sed's regular expressions and replacement strings.

That ^L is a pesky character. I've tried the above in sed and / or awk, used the octal \014 and the ^L, escaped it, quoted it, and everything else I could think to do, then directed it into a file and it is still there. Crazy.

Maybe we could help if you told us what you want to do with the form-feed character. Putting a form-feed in a string isn't going to make it disappear from a file.

Try this. It will get rid of all control characters, and retain newline:

tr -cd "[[:print:]]\n" < file