I've got multiple-line text files of (sometimes) tab-delimited data. I'd like to output the file so I can glance over it - so I'd like to only see the first 80 characters of each line (I designed the text file to put the important stuff first on each line).
I'd thought I could use cat to read each line of the file, and send each line to the next command in a pipe:
cat tabfile | cut -c -80
But that seemed broken. I tried monkeying around, and grep appeared to work - but then I found out that, no it didn't (not every line in the file had 80+ characters) - it appears tabs are counted as single characters by cut.
cat tabfile | tr \t \040 | cut -c -80
Even though that would mangle my data a bit, by eliminating the white-space readability. But that didn't work. Neither did:
cat tabfile | tr \011 \040 | cut -c -80
Maybe I'm using tr wrong? I've had trouble with tr before, wanting to remove multiple spaces (appears the version of tr that I have access to on this machine has an -s option for squeezing down multiple characters - I may need to play with it more)
I'm sure if I messed around I could use perl, awk or sed, or something to do this.
However, I'd like a solution that uses (POSIX?) regular commands, so that it's as portable as possible. If I do end up using tr, I'd probably eventually try turning tabs into characters, maybe do a calculation, cut on the calculation, and then turn those characters back into tabs for the output.
It doesn't need to be a single line / entered directly on the command line - a script is fine.
More info on tab-files:
I use tab to break fields, because someday I may want to import data into some other program. So I tend to have only one tab between pieces of content. But I also use tabs to align things with vertical columns, to aid in readability when looking at the plain text file. Which means for some pieces of text I pad the end of the content with spaces until I get to where the tab will work in lining up the next field with the ones above and below it.
DarkTurquoise #00CED1 Seas, Skies, Rowboats Nature MediumSpringGreen #00FA9A Useful for trees Magic Lime #00FF00 Only for use on spring chickens and fru$