Using the Linux Subsystem for Windows (LSW), clip.exe can be used to copy data to the windows clipboard:
$ clip.exe /?
CLIP
Description:
Redirects output of command line tools to the Windows clipboard.
This text output can then be pasted into other programs.
Parameter List:
/? Displays this help message.
Examples:
DIR | CLIP Places a copy of the current directory
listing into the Windows clipboard.
CLIP < README.TXT Places a copy of the text from readme.txt
on to the Windows clipboard.
Is there any way to pipe FROM the clipboard? Examples of intended use:
$ paste.exe > foo.txt
$ paste.exe | tr , '\n' | clip.exe
Solution
This prints the Windows' clipboard to stdout:
powershell.exe Get-Clipboard
Examples
$ echo "hello" | clip.exe
$ powershell.exe Get-Clipboard
hello
$ date +%Y-%m-%d | clip.exe
$ powershell.exe Get-Clipboard
2019-06-13
$ alias paste.exe='powershell.exe Get-Clipboard'
$ echo "world" | clip.exe
$ paste.exe
world
paste() { # Add me to your .bashrc, perhaps.
powershell.exe Get-Clipboard | sed 's/\r$//'
# The `sed` will remove the unwelcome carriage-returns
}
source: https://github.com/Microsoft/WSL/issues/1069#issuecomment-391968532
Related
I need to get stdout echoed onto the command prompt and appended into a file.
I have tried echo "foo" | tee -a log.txt. I have looked on google, however these is nothing there that is relevant.
"foo" | tee -a log.txt
It should echo foo and append it to a file. Instead I get
'tee' is not recognized as an internal or external command,
operable program or batch file.
I don't want the command tee, I need to get stdout echoed onto the command prompt
Pass what your trying into power shell, like this:
powershell "echo foo | tee -a foo.txt"
working a script that lists or outputs specific files on a windows machine directory when executed a script from a Linux server
Here is the current script we got, it lists all contents in the windows directory but my requirement is to filter out the required ones
echo "ls -l ${TARGET_ICT_DIR}\nquit\n" | sftp ${SFTP_LOGIN} | tee /tmp/ver_ict_rel_dest_${L_CURR_PID}.txt
The above command outputs all files in that windows directory but im looking for files that only searches below files:
anchor.jar
rename.txt
zipper.dat
Please suggest
Will this insertion of grep in the pipeline do the trick?
echo "ls -l ${TARGET_ICT_DIR}\nquit\n" |
sftp ${SFTP_LOGIN} |
grep -E ' (anchor\.jar|rename\.txt|zipper.dat)\r?$' |
tee /tmp/ver_ict_rel_dest_${L_CURR_PID}.txt
Do not know if the check for \r is necessary -- but... Windows... Also, in comment #ghoti noted that \r might not translate well to all versions of grep and shell. You could try something like the following if you run into such:
echo "ls -l ${TARGET_ICT_DIR}\nquit\n" |
sftp ${SFTP_LOGIN} |
grep -E " (anchor\.jar|rename\.txt|zipper.dat)$(printf '\r')?$" |
tee /tmp/ver_ict_rel_dest_${L_CURR_PID}.txt
(Both variants of the ls -l | grep -E ... part was tested with dash and bash on Linux.)
i used below one and it satisfied my condition
echo "ls -l {anchor.jar,rename.txt,zipper.dat} ${TARGET_ICT_DIR}\nquit\n" | sftp ${SFTP_LOGIN} | tee /tmp/ver_ict_rel_dest_${L_CURR_PID}.txt
I have a test script that contains the following:
lp -d HP ~/cap/alpha/error
HP is a designated printer on my wireless network and ~/cap/alpha/error is the full file path to the file containing the report from a python unit test.
The command works from the terminal window but not from the script called test.
I can't figure out why this is not working?
How to pipe stdout while keeping it on screen ? (and not to a output file) (answer by jilliagre):
echo 'ee' | tee /dev/tty | foo
This answer worked for me as follows:
$ python3 "mytest.py" | tee /dev/tty/ | lp -d brother
printing to both my terminal and my printer.
I want to set up a teamspeak bot, and I have this script to start this.
#!/bin/bash
if [ $1 = 'stop' ]
then
echo stop >> /root/ts3bot/tmp/log.txt
date >>/root/ts3bot/tmp/log.txt
echo ======================
screen -S bot -X quit
fi
if [ $1 = 'start' ]
then
echo start >> /root/ts3bot/tmp/log.txt
date >> /root/ts3bot/tmp/log.txt
echo ======================
screen -dmS bot php core.php
ps ax | grep -v grep | grep -v -i SCREEN | grep links >> /root/ts3bot/tmp/log.txt
fi
<here is an extra blank line>
but when I type bash bot.sh it says syntax error: unexpected end of file
I don't know what I did wrong :/ the chmod is set on 755
Thanks!
I suspect you may have copied this shell script from a Microsoft Windows box over to a Linux or Unix server. If so, the problem might be that you have DOS/Windows line endings, which can cause unpredictable results in scripts.
To check the script for bad line endings on a Linux or Unix server, you can dump the file (sort of like a hex dump) by typing the following at the shell prompt:
$ od -c bot.sh | less
And look for \n or \r or \r\n. If lines appear to have a \r at the end, then you've found the problem.
To FIX this line-ending problem, you can use a tool like dos2unix if it's installed on your system. If you don't have dos2unix but you're on a Linux server, you may be able to do this instead:
$ sed -i 's/\r//' bot.sh
to convert the file.
Lastly ... see the first line of the script, #!/bin/bash? Because of that, you don't need to run this with bash bot.sh, you can just execute it directly with ./bot.sh.
So I've made a script which is collecting data from many different files:
#!/bin/bash
mkdir DATAPOOL"$1"
grep achi *out>runner
grep treat *out>>runner
cat runner | grep Primitive *gout | grep '= '|awk '{print $1,$6}' > CellVolume"$1".txt
cat runner | grep ' c ' *gout | grep 'Angstrom '|awk '{print $1,$3}' > Cellc"$1".txt
cat runner | grep 'Final energy ' *gout |awk '{print $1,$5}' > CellEnergy"$1".txt
etc etc
cat runner |awk '{print "~/xtlanal",$1," > ",$1}' >runner2
vi runner2
:1,$s/gout:/xtl/
:1,$s/gout:/dat/
:wq
source runner2
grep Summary *dat | grep 'CAT-O ' |awk '{print $1,$6}' > AVE_NaO_"$1".txt
mv *txt DATAPOOL"$1"
So I end up with all the required text files when run without the vi part and so I know it all works. Furthermore when I run it with the vi commands, it just stops running at the vi command and then i can manually enter the 3 commands and I end up with the correct results. What I'm struggling with is I cant get vi to run the commands on its own so I can just execute the file multiple times within different directories and not have to manually enter commands time and time again.
Any help would be greatly appreciated.
Cheers
something like this as a bash script:
#!/bin/bash
vi filename.txt -c ':g/^/m0' -c ':wq'
where -c execute a command. Here the command is to reverse the lines in a textfile. After done, :wq to save and exit. (man vi to get more about -c)
If you don't want to type -c twice, you can do it this way:
vi -c "g/^/m0 | wq" filename.txt
For scripted editing tasks, you can use ed instead of vi:
ed runner2 <<'END'
1,$s/gout:/xtl/
1,$s/gout:/dat/
w
q
END
For global line-oriented search and replace, sed is a good choice:
sed -i 's/gout:/xtl/; s/gout:/dat/' runner2
Tested on VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Apr 10 2018 21:31:58)
The vi -c "g/^/m0 | wq" filename.txt may appear to work, but it does not actually!
Typing vi -c "g/^/m0 | wq" filename.txt will result in vi writing and quitting before any major changes are made to the file. (using the pipe in this situation will attempt to execute the wq line by line forcing it to quit before the intended operation)
In order to see a demonstration try typing it without the q and see how slow it works writing line by line:
vi -c "g/^/m0 | w" filename.txt
The more efficient way is using -c as B. Kocis states, or use +.
As B. Kocis stated:
#!/bin/bash
vi filename.txt -c ':g/^/m0' -c ':wq'
or
vi filename.txt +g/^/m0 +wq