christianmlong + pipe   9

Shell command to sum integers, one per line? - Stack Overflow
python -c "import sys; print sum(int(l) for l in sys.stdin)"
python  shell  sum  integers  pipe  stdin 
october 2016 by christianmlong
shell - Processing bash variable with sed - Unix & Linux Stack Exchange
sed is expecting filenames as its second, third, etc. parameters, and if it doesn't find any filenames, it reads from its standard input. So if you have text that you want to process that's not in a file, you have to pipe it to sed. The most straightforward way is this:

echo "blah blah" | sed 's/blah/blam/g'

So your example would become:

LAT=$(echo "$LATLNG" | sed 's/(\(.*\),\(.*\))/\1/g')
LON=$(echo "$LATLNG" | sed 's/(\(.*\),\(.*\))/\2/g')
bash  sed  regex  pipe  shell 
may 2016 by christianmlong
shell - force git status to output color on the terminal (inside a script) - Stack Overflow
To avoid changing your git config, you can do this just for the current command by passing the config variable with -c:

git -c color.status=always status | less -REX

That variable is for the status command only.

If you want the same behaviour for other commands, like diff, show and log, then the variable is color.ui:

git -c color.ui=always diff | less -REX

Note that -c must become before the status or diff argument, and not after.
git  status  color  log  pipe 
may 2016 by christianmlong
Using tar and ssh to efficiently copy files preserving permissions | Me in IT
This trick will tar a directory from a computer, but the file that it would normally create, is standard out, so it is redirected back to the script on the computer you are working on. The computer you are working on extracts the information directly, so there is no location where (redundant) files are stored.

ssh user@machine-where-precious-data-is "tar czpf - /some/important/data" | tar xzpf - -C /new/root/directory
ssh  tar  remote  pipe  transfer  file 
january 2016 by christianmlong
Piping TAR datastream over SSH | BLOG.BRAVI.ORG
2. Offsite backups
This is pretty much the same as above, except we want to transfer a bunch of files and leave them as a tarball on the server rather than as a bunch of files.

$ tar zcf - tobearchived | \
ssh user@destination_server_ip \
'cat - > tobearchived.tar.gz'
ssh  tar  remote  pipe  transfer 
january 2016 by christianmlong
linux - How do I use sudo to redirect output to a location I don't have permission to write to? - Stack Overflow
Your command does not work because the redirection is performed by your shell which does not have the permission to write to /root/test.out. The redirection of the output is not performed by sudo.

There are multiple solutions:

Run a shell with sudo and give the command to it by using the -c option:

sudo sh -c 'ls -hal /root/ > /root/test.out'

Create a script with your commands and run that script with sudo:

#!/bin/sh

ls -hal /root/ > /root/test.out

Run sudo ls.sh

Launch a shell with sudo and then run your commands:

$ sudo -s

% ls -hal /root/ > /root/test.out

% ^D

$

Use sudo tee (if you have to escape a lot when using the -c option):

sudo ls -hal /root/ | sudo tee /root/test.out > /dev/null

The redirect to /dev/null is needed to stop tee from outputting to the screen. Just in case someone needs it: to append to the output file, use tee -a or tee --append.
linux  bash  sudo  pipe  tee 
may 2011 by christianmlong

Copy this bookmark:



description:


tags: