I want a shortcut key to clear the screen in my (Windows 7) psql console just like CTRL-l clears the screen in my R console. I am tired of typing '! cls'. Do I need to write a macro for this? I am running Postgres 9.35. '\r' resets the query buffer but does not clear the screen.
As an alternative to Ctrl-L use, e.g. for scripts in an linux environment:
\! clear
or
\! cls
for Microsoft.
Please use: CTRL + L
Check out the link: http://postgresql.nabble.com/psql-in-bash-how-to-clear-screen-td2141886.html
In case CTRL + L doesn't work on the Windows OS, use:
\! cls
Ensure there is SPACE between \! and cls, hit ENTER.
\! cls + Enter
can be usedfor Windows 10
This works for me using postgresql in Windows 10 with Bash:
\! clear
When using psql ((PostgreSQL) 14.4) through linux terminal just use:
CTRL + Shift + L
It will clear outputs and move cursor to the top of terminal window.
:)
If you're using WSL and a Docker Container, only works with:
\clear
Related
First question ever and it's pretty simple. I've been reading about readline shortcuts in bash terminal, but I cannot get the incremental undo to work with Ctrl+_, Ctrl+x, or Ctrl+u as documented for bash.
I'm using CentOS 7 and echo $0 indicates I'm using bash shell. Thanks much in advance.
so, first of all, i now realize my question was poor (i.e. what bash shell in what os?) . . . but turns out that shortcuts do care about flavor of linux and bash in centos is not exactly the same as bash in WSL on Windows 10 (obviously since that's ubuntu by default)
but the most embarassing part is that the Ctrl+_ shortcut in particular was not working because the underline requires a shift . . . oy . . .
I'm currently trying to setup cronjobs using whenever on an AWS server, but when i try to run the script/rails file I get the following message:
-bash: script/rails: /usr/bin/ruby^M: bad interpreter: No such file or directory
While the script/rails file contains the following:
#!/usr/bin/ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
It looks like to me for whatever reason an extra ^M is being appended to the first line. Also note that I'm developing on windows and deploying to an AWS ubuntu server. Does anyone have an idea of how I can fix this issue? I'm trying to give as much guidance as i can, but this is a weird problem. Note: I tried just creating the file on the ubuntu machine through ssh but it then tries to execute rails itself when i do script/rails.
Thanks,
Cody
Could be a line ending issue where windows represents newlines differently than linux so when you uploaded the file it won't be interpreted properly. If you open the file with vim or vi on your server you should see the ^M (Control-M) character visible at the end of the line.
If you're uploading via ftp you can try uploading that file in binmode and that may resolve it. Otherwise you can open the file and remove the offending character on your server with vi: http://www.tech-recipes.com/rx/150/remove-m-characters-at-end-of-lines-in-vi/. Hope that helps.
I'm assuming you created this script on a windows computer. Windows uses \r\n for it's carriage return (new line character) where as linux simply uses \n. What this means is that when you take a script written on windows and transfer it onto a linux machine then the extra \r characters sometimes get displayed as ^M. There are a few fixes, one of the simplest is simply to run the file through sed and replace these characters:
sed -i 's/\r$//' filename
for instance:
➜ echo -ne "hello\r\nworld" > example.txt
➜ cat example.txt | od -c
0000000 h e l l o \r \n w o r l d
0000014
➜ sed -i 's/\r$//' example.txt
➜ cat example.txt | od -c
0000000 h e l l o \n w o r l d
Additional options can be found here.
I want to grep 2 patterns in a file on Solaris UNIX.
That is grep 'pattern1 OR pattern2' filename.
The following command does NOT work:
grep 'pattern1\|pattern2' filename
What is wrong with this command?
NOTE: I am on Solaris
What operating system are you on?
It will work with on systems with GNU grep, but on BSD, Solaris, etc., \| is not supported.
Try egrep or grep -E, e.g.
egrep 'pattern1|pattern2'
If you want POSIX functionality (i.e. Linux-like behavior) you can put the POSIX 2-compatible binaries at the beginning of your path:
$ echo $PATH
/usr/xpg4/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:[...]
There is also /usr/xpg6 which is POSIX 1 compatible.
/usr/bin: SVID/XPG3
/usr/xpg4/bin: POSIX.2/POSIX.2a/SUS/SUSv2/XPG4
/usr/xpg6/bin: POSIX.1-2001/SUSv3
That command works fine for me. Please add additional information such as your platform and the exact regular expression and file contents you're using (minimized to the smallest example that still reproduces the issue). (I would add a comment to your post but don't have enough reputation.)
That should be correct. Make sure that you do or don't add the appropriate spaces i.e. "pattern1\|pattern2" vs "pattern1\| pattern2".
Are you sure you aren't just having problems with cases or something? try the -i switch.
That depends entirely on what pattern1 and pattern2 are. If they're just words, it should work, otherwise you'll need:
grep '\(pattern1\)\|\(pattern2\)'
An arcane method using fgrep (ie: fixed strings) that works on Solaris 10...
Provide a pattern-list, with each pattern separated by a NEWLINE, yet quoted so as to be interpreted by the shell as one word:-
fgrep 'pattern1
pattern2' filename
This method also works for grep, fgrep and egrep in /usr/xpg4/bin, although the pipe-delimited ERE in any egrep is sometimes the least fussy.
You can insert arbitrary newlines in a string if your shell allows history-editing, eg: in bash issue C-v C-j in either emacs mode or vi-command mode.
egrep -e "string1|string2" works for me in SunOS 5.9 (Solaris)
Well, I have a file test.txt
#test.txt
odsdsdoddf112 test1_for_grep
dad23392eeedJ test2 for grep
Hello World test
garbage
I want to extract strings which have got a space after them. I used following expression and it worked
grep -o [[:alnum:]]*.[[:blank:]] test.txt
Its output is
odsdsdoddf112
dad23392eeedJ
test2
for
Hello
World
But problem is grep prints all the strings that have got space after them, where as I want it to stop after first match on a line and then proceed to second line.
Which expression should I use here, in order to make it stop after first match and move to next line?
This problem may be solved with gawk or some other tool, but I will appreciate a solution which uses grep only.
Edit
I using GNU grep 2.5.1 on a Linux system, if that is relevant.
Edit
With the help of the answers given below, I tried my luck with
grep -o ^[[:alnum:]]* test.txt
grep -Eo ^[[:alnum:]]+ test.txt
and both gave me correct answers.
Now what surprises me is that I tried using
grep -Eo "^[[:alnum:]]+[[:blank:]]" test.txt
as suggested here but didn't get the correct answer.
Here is the output on my terminal
odsdsdoddf112
dad23392eeedJ
test2
for
Hello
World
But comments from RichieHindle and Adrian Pronk, shows that they got correct output on their systems. Anyone with some idea that why I too am not getting the same result on my system. Any idea? Any help will be appreciated.
Edit
Well, it seems that grep 2.5.1 has some bug because of which my output wasn't correct. I installed grep 2.5.4, now it is working correctly. Please see this link for details.
If you're sure you have no leading whitespace, add a ^ to match only at the start of a line, and change the * to a + to match only when you have one or more alphanumeric characters. (That means adding -E to use extended regular expressions).
grep -Eo "^[[:alnum:]]+[[:blank:]]" test.txt
(I also removed the . from the middle; I'm not sure what that was doing there?)
As the questioner discovered, this is a bug in versions of GNU grep prior to 2.5.3. The bug allows a caret to match after the end of a previous match, not just at beginning of line.
This bug is still present in other versions of grep, for instance in Mac OS X 10.9.4.
There isn't a universal workaround, but in the some examples, like non-spaces followed by a space, you can often get the desired behavior by leaving off the delimiter. That is, search for '[^ ]*' rather than '[^ ]* '.
grep -oe "^[^ ]* " test.txt
If we want to extract all meaningful input before garbage and actually stop on first match then -B NUM, --before-context=NUM option may be useful to "print NUM lines of leading context before matching lines".
Example:
grep --before-context=999999 "Hello World test"
I'm using ubuntu and I call gedit by using this command:'sudo gedit filename.java'. I'm newbie in ubuntu so now I can not located that file. Ah I'm using windows XP and ubuntu and I have three disk C,D and E in windows XP the fourth disk for ubuntu is not display in windows XP. Can anyone show me where I can find my file? Thank you very much!
Try looking up the command "find". It will locate files.
The next time you need to find a file and you don't know where it is, just use the locate program included with Ubuntu. Sure, your file most likely won't show up immediately in the slocate database, but it's a really good searcher.
Also, the command line and the run prompt assume that the starting point, that is, the current working directory is always "~" unless you've set it differently. That means that all files and paths are relative to your home folder: /home/username for a user and /root for the root user.
Finally, you do not need to use the sudo command for writing code in your own home directory, and thus you can just stick with gedit filename.java. However, if you ever do need to use a graphical application with root/superuser privileges, use gksu for GTK apps and kdesu for KDE apps. sudo is for when you are running an program or need elevated privileges in a terminal.
Type "man find" into the terminal to get a description of how to use the command. But first place I'd look is the home folder. Open up the terminal and type "~" without quotes.
Open a terminal again ( from where you initially typed sudo ) and type ls -l you have to find it there.