sed extract every nth line.
Generic is:
sed -n 'STARTPOSITION,${p;n;*LINE}' foo
where n;*LINE = how many lines. thus p;n;n; is "for every 3 lines" and p;n;n;n;n; is "for every 5 lines"
Show Sample Output
This should work even if the output format changes.
List everyone who committed to a particular project, listed alphabetically. To list by commits, add -n to the shortlog. Show Sample Output
Recursively rename .JPG to .jpg using standard find and mv. It's generally better to use a standard tool if doing so is not much more difficult.
In bash, by pressing ALT+n and then a character x, x will be printed n times I know is not the same as the original command, but is correlated. Show Sample Output
If you don't have nl on your system, this achieves a similar effect, the default behavior in nl is to not number blank lines, but this does.
I needed to add a line to my crontab from within a script and didn't want to have to write my own temporary file.
You may find you need to reload the crond after this to make the change take effect.
e.g.:
if [ -x /sbin/service ]
then
/sbin/service crond reload
else
CRON_PID=`ps -furoot | awk '/[^a-z]cron(d)?$/{print $2}'`
if [ -n "$CRON_PID" ]
then
kill -HUP $CRON_PID
fi
fi
The reason I had CRON_HOUR and CRON_MINS instead of numbers is that I wanted to generate a random time between midnight & 6AM to run the job, which I did with:
CRON_HOUR=`/usr/bin/perl -e 'printf "%02d\n", int(rand(6))'`
CRON_MINS=`/usr/bin/perl -e 'printf "%02d\n", int(rand(60));'`
Better -and faster- using bash printf. Show Sample Output
You can substitute /home/$USER with any path you like.
Replace 70 with the desired height. Replace 180 with the desired width. I put it in my bashrc, because by default my terminal is too small.
You're a developer - but it doesn't mean you have to slum it! Why not spice up your man page lookups by using a decent PDF viewer. I use 'xpdf' - maybe you prefer acroread, whatever, it's just as fast as plain dull ASCII on today's machines and you can still search for stuff - that's the main reason I use PDF and not PS.
Often you find some tty programs are messed up and confused about character encoding - 'man' is a common problem and sometimes displays weird characters for apostrophes, hyphens etc etc. Another class of programs that suffer from this are those that try to use the line drawing characters - eg RedHat's tty system admin functions such as system-config-firewall-tui system-config-network-tui etc. Adding 'LC_ALL=C' fixes most of these problems (as long as you want English! Perhaps speakers of other languages can add a comment here). For bonus points, I've added the '-c' option to the man command so that it ignores it's cache and re-computes the man page using the C locale.
connects to host via ssh and displays the live transfer speed, directing all transferred data to /dev/null needs pv installed Debian: 'apt-get install pv' Fedora: 'yum install pv' (may need the 'extras' repository enabled) Show Sample Output
You can use
vim scp://root@example.com//file
too in a simple case.
the sql command lpad and rpad using sed
for lpad, invert the &_ with _&:
ls / | sed -e :a -e 's/^.\{1,15\}$/_$/;ta'
Show Sample Output
the sed way to print a linhe with 50 hyphens
Perl is installed by default on most modern OS when jot is not. Show Sample Output
sed already has an option for editing files in place and making backup copies of the old file. -i will edit a file in place and if you give it an argument, it will make a backup file using that string as an extension.
Change the number 50 to whatever number of characters you want. Change the character inside the double quotes to whatever you want printed.
Works in RHEL5 and derivatives.
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: