LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-29-2017, 09:54 AM   #1
MrMeeSeeks
Member
 
Registered: Jan 2017
Posts: 32

Rep: Reputation: Disabled
how to set 'head' output width


Hey,

I'm working on a script that runs through a bunch of MT940 files, but since I'm pretty new to this stuff I'm using head quite often to make sure I still got the formatting correct.

However, head insists on using about 60 columns for it's output, making it pretty inconvenient to read and understand long lines. Other programs like ls and echo don't show this behaviour, they just go by $COLUMNS which is 180.
Now the best thing I found so far was someone recommending (in a slightly different context) to set the env variable COLUMNS specific to a command, which seemed to work for the problem in question. The set command was something like "COLUMNS = 180 'command_name' -c -b -n 1 > 'command_name'.log"
Now, not only did this not work for me - just went into some loop without output trying that -, on a minor note: I don't even understand the flags here, so could someone tell me in what man or info I could read up on this? Is it somewhere in the maze of the man bash?

Nevermind, my actual problem is: how do I set the number of columns head will use for its output?
Aaaaand ... why does head | echo not work?

Sorry for this being my first post - I'm afraid I'll have to threaten it won't be my last though - and thanks for any help.

Best wishes

//sorry:
running bash version 4.3.46(1)-release

Last edited by MrMeeSeeks; 01-29-2017 at 10:10 AM.
 
Old 01-29-2017, 10:09 AM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,547

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
I've never seen the head command show anything but complete lines unless you use the "-c" option to get the first {n} characters rather than counting lines. What does "head --version" show on your system? The head command is not a bash builtin. It is a separate command.

The echo command just echoes its arguments. It does not read from stdin.

Last edited by rknichols; 01-29-2017 at 10:11 AM.
 
1 members found this post helpful.
Old 01-29-2017, 10:15 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,614
Blog Entries: 3

Rep: Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860
You're probably looking for fold, which can wrap the width to a specific width.

Code:
head -n 5 somefile | fold --width=79
Each small program specializes in one specific task.
 
Old 01-29-2017, 10:23 AM   #4
MrMeeSeeks
Member
 
Registered: Jan 2017
Posts: 32

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rknichols View Post
I've never seen the head command show anything but complete lines unless you use the "-c" option to get the first {n} characters rather than counting lines. What does "head --version" show on your system? The head command is not a bash builtin. It is a separate command.

The echo command just echoes its arguments. It does not read from stdin.
head is version 8.25.
I just figured the actual file I'm running head on is formatted that way for reasons beyond my grasp, so I'm just a dummy. I guess I'll have to write me something that kills unnecessary line breaks but respects the MT940 format. So guess I'll read up on regexes. Man this does not feel at all like I'm in a galaxy far far away from what I actually wanted to accomplish.

Thanks for the note on echo!
 
Old 01-29-2017, 12:46 PM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,614
Blog Entries: 3

Rep: Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860Reputation: 2860
I see that I probably got the idea reversed. If you want to expand to a specific width you can use fmt

Code:
head -n 5 somefile | fmt --width=170
 
Old 01-29-2017, 01:37 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,547

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
Looks like you will have some fun parsing that MT940 format. Looks to me like a job for perl or awk.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tab width in Bash - how do I set it benr77 Linux - General 8 12-04-2012 10:53 AM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
dvd-slideshow: when playing output video with mplayer width is too large kyroii Linux - Software 0 01-11-2008 02:22 AM
Which ivtvfbctl or ivtvctl option to set the width of the picture? lagu2653 Linux - Hardware 0 12-07-2005 03:45 AM
Set text (runlevel 3) console character width davee Linux - Newbie 2 11-16-2003 03:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration