Get a specific line from file and print tab characters in Linux


I run into this once in a great while, but can never remember. We have large data imports that have a tab out of place or invalid data in output. Thankfully our importer shows the line number. When you need to find line 39,000-something, its much easier to ask for it directly. Sed does that, among other tools. And sed can output the \t stops.

sed '39432,39432!d' file.txt

The above grabs a range of lines, but I just wanted one. I’m sure the command is different if you want just one. Actually…. yeah…

sed '39432!d' file.txt

That outputs to terminal the one single line 39432. Now let’s also output the tabs and whitespace characters:

sed '39432!d' file.txt | sed -n 'l'
050000\t2021 PROGRAM\t01000003\tO\tW\tNO ORDER DESCRIPTION\t.00\t.00\t.0\
0\t.00\t.00\t    \tNET, 01/10/2021\t.00\t2020-12-07\t          \t    \
      \t\tY\tORDERING LOCATION\t          \t00000000000\t \
\tT2021\r$

Well, that looks like a mess, but I can see the tab locations in data output easily. Makes it faster to locate a data error and fix in source programs.