Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux command to view raw file, including its delimiters

I'm trying to view the content of a file including its delimiters in terminal. For example:

hello\t\tworld\n
hello\t\tworld\t\tagain\n

instead of just:

hello world
hello world again

I did this once awhile ago using either "sed" or "awk"....I think...but, I can't seem to remember any of it now.

Thanks for the help.

like image 913
wi3o Avatar asked Feb 08 '23 19:02

wi3o


2 Answers

VI can show you this if open the file in it and type :set list.

e.g.

$ cat test.txt
hello           world
hello           world           again

In VI the ^I are tabs and $ are Line Feeds.

enter image description here

Also like the comment states - cat -A will get you the same output:

$ cat -A test.txt
hello^I^Iworld$
hello^I^Iworld^I^Iagain$
like image 74
zzevannn Avatar answered Feb 13 '23 03:02

zzevannn


you can use od command,

od -t a input_file | awk '{$1=""}1' | 
awk 'BEGIN{RS="[ \t\n]+";ORS="";
    d["sp"]=" "; d["nl"]="\\n\n"; d["ht"]="\\t"; d["cr"] = "\\r";
}length($0)>1{$0=d[$0]}1'

with input_file

hello       world
hello       world again

you get,

hello\t\tworld\n
hello\t\tworld again\n
like image 38
Jose Ricardo Bustos M. Avatar answered Feb 13 '23 02:02

Jose Ricardo Bustos M.