Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
It's now hard to write one without the capability of freezing the header, like
function viewcsv() {
cat $1 | sed -e "s/,,/, ,/g" | column -s, -t | less -#2 -N -S
}
But is there a utility that allows me to freeze the header, or change the one above to allow it?
[EDIT:] by freezing the header I mean when I scroll up and down with "less", the first line remains there on the top of the screen. Those are usually the header information I want to see even when scrolling down thousands of lines, such as "Date", "Symbol", etc.
I adapted this How to scroll large datafile while keeping header to your wishes:
vim -R -u NONE -N +'map <right> 2zl
map <left> 2zh
map q :qa<CR>
se nu sbo=hor scb nowrap
1sp
winc w
' <(sed -e "s/,,/, ,/g" $1|column -ts,)
-R Readonly mode.
-u NONE all
initializations from files and environment variables are
skipped (they could interfere with the working of e. g. winc w)
-N Not compatible mode (otherwise key names like <right> might not work)
map <right> 2zl to make → scroll horizontally like less -#2
map <left> 2zh to make ← scroll horizontally like less -#2
map q :qa<CR> to make Q quit like less
se nu sbo=hor scb nowrap set options:
'number' - Print the line number in front of each line.
'scrollopt'=hor - Bind horizontal scrolling for 'scrollbind' windows
'scrollbind' - to scroll the header line together with the rest of the data
'nowrap' - lines will not wrap
and only part of long lines will be displayed.
1sp Split current window in two (new window has 1 line, the header)
winc w move cursor to body window
Off the top of my head, you could tailor the less prompt to display the CSV headers instead of the usual prompt.
viewcsv () {
less -PM"$(sed -n 's/,/ /gp;q' "$1")" -M -N -S "$1"
}
(You can still see where you are in the file with = -- I suppose you could replace the short or medium prompt just as well.)
If your data contains percent signs or question marks, they will need to be escaped, as these have a special meaning in the less prompt definition. See the description of the -P option and the section PROMPTS in the less manual for details.
Maybe you could even throw in some terminal escape sequences to get the prompt (or part of it) displayed at the top of the screen, but the trivial solution would superimpose the prompt over data you want to see.
Are you just asking about not changing the first line? (It's not at all clear to me what you mean by 'freezing', but 'not modifying' seems like a reasonable interpretation.)
viewcsv() {
sed -e "1!s/,,/, ,/g" "$1" | column -s, -t | less -#2 -N -S
}
(Removed the redundant keyword 'function' and the UUOC. The relevant addition is the address scope 1! in sed.)
Or perhaps you mean that you want the first line to not go through column:
viewcsv() {
{ sed 1q "$1"; sed -e 1d -e 's/,,/, ,/g' "$1" |
column -s, -t; } | less -#2 -N -S
}
Related
So I did an OS version-up in a linux server, and was seeing if any setting has been changed.
And when I typed "sysctl -a | grep "net.ipv4.ip_forward"
The following line was added,
net.ipv4.ip_forward_use_pmtu = 0
I know that this is because this parameter is in /proc/sys.
But I think if the result of sysctl before upload did not show this line, it was not in /proc/sys before as well, right ?
I know that 0 means " this setting is not applied...So basically it does not do anything.
But why this line is added.
The question is
Is there any possible reason that can add this line?
Thank you, ahead.
Even the question itself "added in the result of sysctl in linux server" is wrong here.
sysctl in the way you invoked it, lists all the entries.
grep which you used to filter those entries "selects" matching texts, if you'd run grep foo against the list:
foo
foobar
both items would be matched. That's exactly what you see but the only difference is instead of "foo" you have "net.ipv4.ip_forward".
Using --color shows that clearly:
Pay attention to the use of fgrep instead of grep because people tend to forget that grep interprets some characters as regular expressions, and the dot . means any character, which might also lead to unexpected matches.
Background.
I am a frequent vim-user, I just love the way you can navigate the buffers without ever having to reach for the mouse. I'm especially fond of the relative line numbers that let's me jump to specific lines with perfect accurecy, it just makes navigating that much faster. I also use tmux quite a bit since I often have a lot of stuff going on in my terminal.
The thing that bugs me the most though is when I use tmux copy-mode, it just takes forever to navigate to the line(s) you want to copy if you are using the arrow-keys, ctrl+p or k.
Searching for a unique keyword in the buffer is also not ideal but it might be faster if you already know what to search for. A lot of the time you make a search only to discover that the keyword you searched wasn't so unique after all and you didn't end up on the line you wished for anyway.
My question is this:
Does tmux support relative line-numbers?
..or line-numbers at all for that matter?
I can't find any information about this on the web. Nobody seems to be mentioning anything about this anywhere. Is there a better way?
Any other tips for ultra-speedy navigation in tmux copy-mode using the keyboard would also be very much appreciated.
tmux has a linenumber system in copy mode. however the first line is very bottom line.
In copy mode you can press : to go to line but there is no option to show linenumber. You can use some vim motions (key-mode was set as vi) in copy-mode, e.g. j k 20j 20k f F t T gg G 20G H L M ^ $ / ? ctrl-u ctrl-d w b ....
I think for copy a block of text, it is enough.. If you think you still cannot "ultra-speedy navigation", make a scenario, let's see how could we copy faster.
check man-page of tmux for details.
I found this tip. It will take you to your line with less keystrokes.
# super fast way to reach copy-mode and search upwards
bind-key / copy-mode \; send-key ?
This is a total hack but it works:
tmux split-window -h -l 3 -b "printf '\e[38;5;0m\e[48;5;226m' \
&& seq 200 1 \
&& echo -n 0 \
&& read" \
&& tmux select-pane -l
(newlines added for readablitiy)
To break this down:
tmux split-window -h -l 3 "command..." splits the pane -h horizontally (that is places a new pane next to the current one rather than above or below) with a -l width of 3 (you're unlikely to need more than 3 digits of line number... 0-999) to the -b left of the current pane and runs the command in it:
printf ... just sets the background colour to yellow and the foreground colour to black... You can omit this bit if you're not feeling fancy :)
seq 200 1 prints line numbers from 200 to 1 - extend if you have a tall screen!
echo -n 0 prints the 0 on the last line, because seq will print a trailing newline and we don't want that
read waits for you to press enter - this is how we block it from closing after the echo has completed
tmux select-pane -l jumps you back to focus on the pane you were working on
Select the pane and press enter to close it.
I would imagine that you can do something add a name for the new pane and create a keybinding for both opening and closing it from the pane you're actually trying to count line numbers on, but for now I'm just using the binding:
bind N split-window -h -l 3 -b "printf '\e[38;5;0m\e[48;5;226m' && seq 200 1 && echo -n 0 && read" \; select-pane -l
I'm currently working on a Unix box and came across this post which I found helpful, in order to learn about cat command in Unix. At the bottom of the page found this line saying: -A = Equivalent to -vET
As I'm new into Unix, I'm unaware of what does this mean actually? For example lets say I've created a file called new using cat and then apply this command to the file:
cat -A new, I tried this command but an error message comes up saying it's and illegal option.
To cut short, wanted to know what does cat -A really mean and how does it effect when I apply it to a file. Any help would be appreciated.
It means show ALL.
Basically its a combination of -vET
E : It will display '$' at the end of every line.
T : It will display tab character as ^I
v : It will use ^ and M-notation
^ and M-notation:
(Display control characters except for LFD(LineFeed or NewLine) and TAB using '^' notation and precede characters that have the high bit set with
'M-') M- notation is a way to display high-bit characters as low bit ones by preceding them with M-
You should read about little-endian and big-endian if you like to know more about M notation.
For example:
!http://i.imgur.com/0DGET5k.png?1
Check your manual page as below and it will list all options avaialable with your command and check is there -A present, if it is not present it is an illegal option.
man cat
It displays non-printing characters
In Mac OS you need to use -e flag and
-e Display non-printing characters (see the -v option), and display a dollar sign (`$') at the end of each line.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a standard text configuration file in Linux (Fedora 20). Most lines should apply all the time, but a few lines need to be "turned on" (uncommented) and "turned off" depending on the machine the file is on. So the file looks like this:
; configuration file
parameter1 = a
parameter2 = b
optparameter1 = z ; only applies to %%machine-1%%
; optparameter1 = x ; only applies to %%machine-2%%
parameter3 = c
; optparameter2 = x ; only applies to %%machine-2%%
optparameter2 = f ; only applies to %%machine-1%%
What I would like to do is run a script that would change the file (or copy the file) altering commenting of the lines based on command line parameters. e.g.
./scriptname -u machine-2 -c machine-1 configurationFileName.conf
This would cause all lines with %%machine-2%% in the end comment to be uncommented (of course, leaving the end comments in tact), and all lines with %%machine-1%% in the end comment to be commented.
Any suggestions on how to do this? Thank you.
The following script will allow you to "turn on" and "turn off" specific lines. In your case, it will "turn off" all lines containing machine-2 and "turn on" lines containing machine-1. The script is as follows:
comm=$1
uncomm=$2
filename=$3
sed -i -e "/$comm/s/^;*/;/" $filename
sed -i -e "/$uncomm/s/^;//" $filename
You run it like this:
./scriptname machine-2 machine-1 configurationFileName.conf
The first sed command adds a semicolon (;) to the lines containing the variable $match, if the line is already commented, it leaves it as is. The second one removes semicolons from the beginning of a line.
Enable config for machine1 (and disable config for machine2) :
$ sed -i -e 's/^;* *\(.*machine-1.*\)/\1/p' \
-e 's/^\(.*machine-2.*\)/;\1/p' configurationFileName.conf
Enable config for machine2 (and disable config for machine1) :
$ sed -i -e 's/^;* *\(.*machine-2.*\)/\1/p' \
-e 's/^\(.*machine-1.*\)/;\1/p' configurationFileName.conf
Be careful because the '-i' sed option will directly modify the "configurationFileName.conf" file.
Is there a way to limit :Ag output so it always takes one line and doesn't blow up the quickfix window?
At the moment it looks like this and it's awful. I can't see filenames, everything is super slow and just sucks:
Update For the record, I scrolled Quickfix window a bit to illustrate the point better. And while it is usable via :cn :cp, I would like to be able to quickly glance over the results with j k.
Looking over the man page, there does not seem to be any way to limit the output built into Ag itself.
Is there another way of limiting the line length? Actually, you do have the built in "cut" command in Linux, e.g. using it on the shell:
ag --column foo | cut -c 1-80
Limit all lines to 80.
Now we have to make ag.vim execute our specially crafted command, for which the g:agprg exists. So the first thing I thought of is this:
let g:agprg='ag --column \| cut -c 1-80' " doesn't work
The problem with this is that the ag.vim plugin just appends extra arguments to the end, and thus you end up executing something like ag --column | cut -c 1-80 something-i-searched-for. Is there a way to directly "insert" the arguments before the |?
One trick is to use a temporary shell function, like this:
f() { ag --column "$#" | cut -c 1-80 }; f something-i-search-for
Unfortunately, we still can't use this. ag.vim checks whether or not the first word is an actual command. So it complains that no executable by the name of "f()" exists. So my final solution:
let g:agprg='true ; f(){ ag --column "$#" \| cut -c 1-80 }; f'
As true always exists and doesn't do anything except return true, this works!
To your actual screenwidth instead of 80, you could use:
let g:agprg='true ; f(){ ag --column "$#" \| cut -c 1-'.(&columns - 6).' }; f'
I added the magic - 6 here to account for the extra characters Vim itself adds.
ag now supports a --width switch. rg has a similar --max-columns switch.
Assuming you are using this plugin. You should add this to your ~/.vimrc as specified by :h g:ag_qhandler
let g:ag_qhandler = 'copen 1'
However you can probably just do let :g:ag_qhandler = 'cc'. This will print the results at the in the bottom. When you move through the quickfix list via :cnext or :cprev it will print the current result as well.
For more help see:
:h g:ag_qhandler
:h :cope
Changing the geometry of the quickfix window won't help you fix your problem: the window is unusable not because of its size but because your search results are polluted by superfluous matches in minimized files.
Minimized JavaScript or CSS is the frontend development's equivalent of a binary and that kind of file should be ignored by search tools, indexing tools, file navigation tools and even version control tools, sometimes, because they are generally irrelevant.
Adding these lines to your ~/.agignore will make Ag search only in actual source files:
*.min*
*-min*
*_min*
*.min.*
bundle
min
vendor
tags
cscope.*
Adjust that list to your liking.