my @a = split(/^/, $text);
terça-feira, 31 de maio de 2011
Perl: Split s String into lines
How to split a string into lines while preserving the trailing "\n":
Perl: How to capture STDOUT and the exit code
Capture the exit code but not STDOUT:
Capture STDOUT but not exit status:
$status = system("command");
Capture STDOUT but not exit status:
$output = `command`;
quinta-feira, 26 de maio de 2011
SSH: Login without password
Generate a pair of authentication keys, but do not enter a passphrase:
$ ssh-keygen -t rsa
$ ssh othermachine mkdir -p .ssh
$ cat .ssh/id_rsa.pub | ssh othermachine 'cat >> .ssh/authorized_keys'
Shell: What are lines which are repeated ?
$ cat file.txt
21421415
42657547
65765234
85685634
24246547
12336467
76545253
12336467
46565865
65464364
34668747
21421415
67475473
$ cat file.txt | sort | uniq -c | \
awk '{ if ($1 > 1) { print $2 } }'
12336467
21421415
quinta-feira, 19 de maio de 2011
Shell: Output the common lines of two text files
One way:
Or using the command 'comm' (man comm for more details):
$ diff --side-by-side file_a file_b | grep -n -v "[|<>]"
Or using the command 'comm' (man comm for more details):
$ comm -12 file_a file_b
segunda-feira, 2 de maio de 2011
Git: Recovering Lost Commits with git reflog and reset
Reviewing lost commits
The reflog command will give you a good history of what’s been happening on the head of your branches. Run it, then find the line that refers to the state that you want to get back to:
... snip ...
cf42fa2... HEAD@{84}: checkout: moving to master
73b9363... HEAD@{85}: commit: Don't symlink to themes on deployment.
547cc1b... HEAD@{86}: commit: Deploy to effectif.com web server.
1dc3298... HEAD@{87}: commit: Updated the theme.
18c3f51... HEAD@{88}: commit: Verify with Google webmaster tools.
26fbb9c... HEAD@{89}: checkout: moving to effectif
The latest entries appear at the top. You can work out which branch each change was made on by looking out for lines that say “checkout: moving to …”. Commits 88 through to 85 (they’re numbered in the second column of the output) were the commits that I’d lost; all I needed to do was to get them back.
Reverting a branch to an earlier state
In short, you need to switch to the correct branch (“effectif” in my case) and then do a hard reset. The --hard options sets the HEAD of the current branch back to the commit that you specify:
The reflog command will give you a good history of what’s been happening on the head of your branches. Run it, then find the line that refers to the state that you want to get back to:
$ git reflog
... snip ...
cf42fa2... HEAD@{84}: checkout: moving to master
73b9363... HEAD@{85}: commit: Don't symlink to themes on deployment.
547cc1b... HEAD@{86}: commit: Deploy to effectif.com web server.
1dc3298... HEAD@{87}: commit: Updated the theme.
18c3f51... HEAD@{88}: commit: Verify with Google webmaster tools.
26fbb9c... HEAD@{89}: checkout: moving to effectif
The latest entries appear at the top. You can work out which branch each change was made on by looking out for lines that say “checkout: moving to …”. Commits 88 through to 85 (they’re numbered in the second column of the output) were the commits that I’d lost; all I needed to do was to get them back.
Reverting a branch to an earlier state
In short, you need to switch to the correct branch (“effectif” in my case) and then do a hard reset. The --hard options sets the HEAD of the current branch back to the commit that you specify:
$ git checkout effectif
$ git reset --hard 73b9363
Assinar:
Postagens (Atom)