Show special characters in Unix while using 'less' Command
less will look in its environment to see if there is a variable named LESS
You can set LESS in one of your ~/.profile (.bash_rc, etc, etc) and then anytime you run less
from the comand line, it will find the LESS.
Try adding this
export LESS="-CQaix4"
This is the setup I use, there are some behaviors embedded in that may confuse you, so you can find out about what all of these mean from the help function in less
, just tap the 'h' key and nose around, or run less --help
.
Edit:
I looked at the help, and noticed there is also an -r
option
-r -R .... --raw-control-chars --RAW-CONTROL-CHARS
Output "raw" control characters.
I agree that cat
may be the most exact match to your stated needs.
cat -vet file | less
Will add '$' at end of each line and convert tab char to visual '^I'.
cat --help
(edited)
-e equivalent to -vE
-E, --show-ends display $ at end of each line
-t equivalent to -vT
-T, --show-tabs display TAB characters as ^I
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
I hope this helps.
linux less command search invisible character
CtrlE means something special at the beginning of the search field regardless of how it is entered. Type another non-"special" character first, then press the sequence, then remove the first character.
grep for special characters in Unix
Tell grep
to treat your input as fixed string using -F
option.
grep -F '*^%Q&$*&^@$&*!^@$*&^&^*&^&' application.log
Option -n
is required to get the line number,
grep -Fn '*^%Q&$*&^@$&*!^@$*&^&^*&^&' application.log
How to find /* in LESS?
When you enter /
in less, the following expression is a regex. As such, *
has special meaning there; /*
thus searches for zero-or-more instances of /
.
To prevent any character from having special meaning, you can enter it as a character class:
/[/][*]
...ensures that both of the characters you're searching for are treated literally. This works in other regular-expression contexts (grep, etc) as well.
That said, the above is somewhat more paranoid than necessary. In my tests, the below work as well:
//[*]
//\*
How to remove all special characters in Linux text
Remove everything except the printable characters (character class [:print:]
), with sed
:
sed $'s/[^[:print:]\t]//g' file.txt
[:print:]
includes:
[:alnum:]
(alpha-numerics)[:punct:]
(punctuations)- space
The ANSI C quoting ($''
) is used for interpreting \t
as literal tab inside $''
(in bash
and alike).
UNIX: Strange output if piped to less
I'm guessing that you have the --color=always
option to ls
set, either through an alias, functions or the LS_COLORS
environment variable and ls
is sending color directives to a non-terminal (that is, your pipe to less
).
Handling special characters in bash script
Please do not post so much in one question. Please one problem per question. One script per question, etc.
Make sure to check your scripts with shellcheck. It will catch your mistakes. See https://mywiki.wooledge.org/Quotes .
- When run without arguments:
filename=("'" name "'")
inside awk script is a invalid way to pass anything with '
quotes to system()
call, so you are getting unterminated '
error, as expected, because there will be 3 '
characters. Fix the AWS script, or better rewrite it in Bash, no need for awk. Maybe rewrite it all in Python or Perl.
Moreover, tmp=(name " " $i);
deletes tabs and multiple spaces from filenames. It's all meant to work with only nice filenames.
The script will break on newlines in filenames anyway.
- When run with arguments:
$@
undergoes word splitting and filename expansion (topics you should research). Word splitting splits the input into words on spaces. Use "$@"
. Quote the expansions.
- What I want:
You'll be doing that with "$@"
- What I tried:
The variable content is irrelevant. You have to change the way you use the variable, not it's content. I.e. use quotes around the use of the variable. Not the content.
- Extra:
You did not quote the expansion. Use "$i"
not $i
. It's "$i"/*
. $1
undergoes word splitting.
And finally, after that all, your script may look like, with GNU tools:
if (($# == 0)); then
set -- *
fi
du -hs0 "$@" |
sort -zh |
sed -z 's/\t/\x00/' |
while IFS= read -r -d '' size && IFS= read -r -d '' file; do
printf "%s " "$size";
ls -d "$file"
done
Also see How can I find and safely handle file names containing newlines, spaces or both? https://mywiki.wooledge.org/BashFAQ/001 .
Also, you can chain any statements:
if stuff; then
stuff1
else
stuff2
fi |
sort -h |
awk -f yourscriptrt
And also don't repeat yourself - use bash arrays:
args=()
if stuff; then
args=(*)
else
args=("$@")
fi
du -hs "${args[@]}" | stuff...
And so that sort
has less work to do, I would put it right after du
, not after parsing.
Related Topics
How to Build a Linux Kernel Module So That It Is Compatible with All Kernel Releases
Crontab Is Not Working on Amazon Ec2 Server
Cuda Compiler Not Working with Gcc 4.5 +
Bash Echo with an $ Character Outside the String
Netfilter-Like Kernel Module to Get Source and Destination Address
How to Build an App for an Old Linux Distribution, and Avoid the Fatal: Kernel Too Old Error
Have One Folder with Files That Have the Same Name But Different File
Execute Script as Another User Whilst Not Being Root
How to Set a Variable Used in a Perl Script as Environment Variable
Perl Fails to Set Locale Even Though It Is Installed
Merge Files with Bash by Primary Key
Matlab Mex Socket Wrapper Library
Bash Sort - How to Sort Using Timestamp