I find this question asked very frequently... So here is the present of day(not for the April 1st, it's already 2nd in China now ;)
$ tac file.in | sed '1,10d' | tac > file.out
Obviously, you could replace 10 with any number you like, Cheers!
a blog on compilers, Linux, software and other technological stuff
I find this question asked very frequently... So here is the present of day(not for the April 1st, it's already 2nd in China now ;)
$ tac file.in | sed '1,10d' | tac > file.out
Obviously, you could replace 10 with any number you like, Cheers!
Abstract: I'm trying to explain the process of bash setup in this article.
Keywords:bash, shell, environment
It is usually hard to answer the question where this variable is set, because there is SO many different files involved. So let's start with some concepts:
$/bin/bash) or by the /bin/su command. It is also started with a terminal program within a graphical environment.An interactive login shell generally initializes with the following configuration files:
/etc/profile -> [~/.bash_profile] -> [~/.bash_login] -> [~/.profile]
In some systems, the /etc/profile script will look for additional settings in /etc/profile.d/*.sh, and the ~/.bash_profile usually sources ~/.bashrc.
When an interactive non-login shell starts, it first copies the environment of its parent shell and then reads its settings in the following order:
/etc/bash.bashrc -> [~/.bashrc]
Remember that only exported variables of its parent shell is copied, functions and aliases of its parent are NOT inherited.
A non-interactive shell simply copies environment from its parent, and does not read any configuration files.
Abstract: Setup an LAN network of only the host and guest.
Recently I'm trying something on qemu and want to access the guest from the host more freely than user mod port redirect, but I do not want to expose my guest to the host network. All I did is to wrap everything into a script:
#!/bin/sh
HOSTIP="192.168.1.250"
GUESTIP="192.168.2.10"
NETMASK="255.255.255.0"
USERID=`whoami`
IFNAME=`sudo tunctl -b -u $USERID`
sudo ifconfig $IFNAME $HOSTIP netmask $NETMASK up
echo ":: Host IP is $HOSTIP"
echo ":: Run the follwing command in guest to set IP and gateway:"
echo " # ifconfig eth0 $GUESTIP"
echo " # route add default gw $HOSTIP"
echo ":: Starting QEMU with TUN/TAP network..."
qemu -hda webdev.qcow \
-boot c -m 256 \
-k en-us -localtime\
-net nic,vlan=0,model=rtl8139 \
-net tap,vlan=0,ifname=$IFNAME,script=no,downscript=no
sudo tunctl -d $IFNAME
HOSTIP="19
Btw, I find sticky note gadget on iGoogle a great tool to share a couple of lines between machines - I'm writing on my Windows laptop and the script is in my Linix desktop, just a few paste and copy brings the script here :)
Abstract: Add modeline to a file can help VIM remember file-specific options.
I've got to port some application to another arch these days, so I have to deal with a lot of files that does not follow my usual coding standards, and I don't want to edit my VIM settings now and then, so I turned to modeline for help.
To add modeline to all the files, I simply did a find & echo like this:
for f in `find . -name '*.cpp' -o -name '*.h' -print0| xargs -0i echo {}`;do echo -e "\n/* vim: set ts=2: */" >> $f;done
Abstract: My scripts to backup vim setting and synchonize between Windows and Linux.
Finally I cannot bare the boring work of copying my vim settings around my labtop(with both windows and linux installed), lab pc and working server. So I write a few scripts to automatic this work for me:)
The first script is used to copy the scirpts to a certain dir on my laptop that can be share accross Windows and Linux systems. tr and sed are used to convert file format and handle some syntax difference.
#!/bin/bash
CURDIR=`pwd`
BACKDIR="/cygdrive/e/vim-setting"
if [ -d $BACKDIR ] ; then
echo "Backup to $BACKDIR"
else
mkdir "$BACKDIR"
echo "Make backup dir $BACKDIR"
fi
cd "$BACKDIR"
rm .vimrc
rm .gvimrc
rm -rf .vim
cp '/cygdrive/c/Documents and Settings/Yuanjie/_vimrc' .vimrc
tr -d '\15\32' < '/cygdrive/c/Documents and Settings/Yuanjie/_gvimrc' | sed 's/set guifont=\([^:]*\):h\([0-9]*\)/set guifont=\1\\ \2/' >.gvimrc
cp -r '/cygdrive/c/Documents and Settings/Yuanjie/vimfiles' .vim
cd $CURDIR
After files are moved to the synchronize folder, I init a git repo and push it to a host. The synchronize script on the Linux side goes like this:
#!/bin/bash
CURDIR=`pwd`
EMOUNT=0
BACKDIR="/media/e/vim-setting"
if [ ! -d "$BACKDIR" ] ; then
echo "trying to mount drive e ..."
pmount /dev/sda9
if [ "$?"=0 ] ; then
echo "drive e mounted"
EMOUNT=1
else
echo "drive e cannot be mounted"
exit
fi
fi
cd $HOME
tar cjf .vim-setting.$(date +%F).tar.bz2 .vim/ .vimrc .gvimrc
rm -rf .vim/ .vimrc .gvimrc
cp -r $BACKDIR/.vim $HOME
cp $BACKDIR/.vimrc $HOME
cp $BACKDIR/.gvimrc $HOME
if [ "$EMOUNT"=1 ] ; then
pumount /dev/sda9
if [ "$?"=0 ] ; then
echo "drive e unmounted"
else
echo "drive e cannot be unmounted"
exit
fi
fi
cd $CURDIR
The scirpt above tar the original setting files and copy the new settings from the synchronize dir. Since the drive is not always mount, a dir test is used and drive will be mounted with pmount. The synchonize scirpt on Windows is similar but simpler than this, but guifont setting in gvimrc will have to be changed back like this:
sed 's/set guifont=\([A-Za-z\\ ]*\)\\ \([0-9]*\)/set guifont=\1:h\2/'
Notice that you may have to modify this in case there's number in your font name...
Abstract
A python script to generate cue file from file names in a same folder is given.
Sometimes we have lessless music (ape, flac…) split in to different files, and a cue file may help orgnize them in some music jukebox application, i.e foobar2000. so I create a really silly script to help me…
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
import sys
import glob
from string import Template
from optparse import OptionParser
cue_head='''REM GENRE $GENRE
REM DATE $DATE
REM DISCID $DISCID
PERFORMER "$PERFORMER"
TITLE "$ALBUMTITLE"'''
cue_file='''
FILE "$FILE" WAVE
TRACK $TRACK AUDIO
TITLE "$TRACKTITLE"
INDEX 01 00:00:00'''
def cue_gen():
"""
generate cue file
"""
parser = OptionParser()
parser.add_option('-d', dest='dir',
type='string')
parser.add_option('-s', dest='sfx',
type='string', default='ape')
options, args = parser.parse_args()
if options.dir is None:
directory = os.getcwd()
else:
directory = options.dir
suffix = options.sfx
print directory, suffix
files = glob.glob(os.path.join(directory, '*.'+suffix))
files = [ff[1] for ff in [os.path.split(f) for f in files]]
files.sort()
for file in files:
print file
begin = int(raw_input('Title offset? '))
genre = raw_input('Genre? ')
date = raw_input('Date? ')
discId = raw_input('DiscId? ')
performer = raw_input('Performer? ')
albumTitle = raw_input('Title? ')
d1 = dict(GENRE = genre,
DATE = date,
DISCID = discId,
PERFORMER = performer,
ALBUMTITLE = albumTitle)
head = Template(cue_head).substitute(d1)
cuepath = os.path.join(directory, (albumTitle+'.cue'))
f = open(cuepath, 'w')
f.write(head)
track = 0
for file in files:
trackTitle = file[begin:-(len(suffix)+1)]
track = track + 1
d2 = dict(FILE = file,
TRACK = track,
TRACKTITLE = trackTitle)
body = Template(cue_file).substitute(d2)
f.write(body)
f.close()
if __name__ == '__main__':
cue_gen()
I know it’s quite rough and a lot of enhancement can be made… maybe it should search for the right file extension automatically or even search the genre for the internet, and that’s just why I put it here, hopefully some of you would help to improve it XD
When you create a bookmark in Acrobat, it automaticly sets the current zoom setting to te bookmark. This may be smart and sweet for someone, but to me it's stupid and annoying. Since when I read a file in a large screen, I want a greater zoom, while on a smaller screen, I wanna save space and see more content; setting a zoom for bookmarks screws things up. Finally I found {a great perl script} that can convert all pdf bookmark to zoom: inherit.
Use the bookmarks-fitpage.pl script from the zip, which set all bookmarks to zoom: inherit (the script is named as fitpage, which is a bit confusing...)
Notice that the script only works for PDF version 1.4 or earlier, if you're using Acrobat 9, you can convert the file to pdf-1.4 (Acrobat 5) by going to menu: advanced>print production>preflight, the wizard will do a nice convert job for you.