You are not logged in.
I present to you torso, the missing link between "head" and "tail"
Usage: torso N [-n M] [FILE]
Prints M lines (default 10) from FILE (or STDIN if FILE is not given), starting at line N
Wow getopt, good job getting it to work, but it looks horrible, doesn't it? I tried using it once and gave up after a few minutes.
Your script works nice, but it prints one line too many.
With these kinds of apps you should make it easier to pipe to it so something like cat -n .bashrc | torso 10 works, now you have to do cat -n .bashrc | torso 10 -
Offline
I really like this idea, how would I use it though? Add to .bashrc or have as separate script?
Thanks
Daenyth wrote:Here's my version of the filetype-agnostic extractor... Dependencies are pacman, bzip2, gzip, p7zip. It also supports tar, gzip, bzip2, cpio, zip, 7zip, rar. Probably others as well..
ex() { [snip] }
That's designed as a function for your .bashrc
Daenyth wrote:I present to you torso, the missing link between "head" and "tail"
Wow getopt, good job getting it to work, but it looks horrible, doesn't it? I tried using it once and gave up after a few minutes.
Yes indeed, getopt is fugly as sin. I copied that section almost verbatim from makepkg; cross makepkg against the manpage and you will begin to understand how it works.
Your script works nice, but it prints one line too many.
Thanks for pointing that out. It's now fixed
With these kinds of apps you should make it easier to pipe to it so something like cat -n .bashrc | torso 10 works, now you have to do cat -n .bashrc | torso 10 -
Huh? The following should work:
torso 10 ~/.bashrc
cat foo bar | torso 10
[git] | [AURpkgs] | [arch-games]
Offline
This would also work: tail -n+starting_line_number file|head -n how_many_lines
Last edited by test1000 (2009-03-21 23:05:07)
KISS = "It can scarcely be denied that the supreme goal of all theory is to make the irreducible basic elements as simple and as few as possible without having to surrender the adequate representation of a single datum of experience." - Albert Einstein
Offline
Of course it would, but that doesn't mean it's easier
Something to consider at least, but I think the sed will be faster for now
[git] | [AURpkgs] | [arch-games]
Offline
i don't think it's hard..
edit: anyway, thanks for the getopts hint. i haven't looked at it yet and have been putting it off..
Last edited by test1000 (2009-03-21 23:10:41)
KISS = "It can scarcely be denied that the supreme goal of all theory is to make the irreducible basic elements as simple and as few as possible without having to surrender the adequate representation of a single datum of experience." - Albert Einstein
Offline
Hi all, first post!
I've been happily using Arch for more than a year, and I must say this is the distro that fits me like a glove (previously I used Gentoo and Debian Sid from a netinstall).
So, nevermind, that was a little introduction (I'm sure there's a thread where new users introduce themselves, but it's redundand IMO). On with my self made comand line utility:
I love listening to audio lectures, podcasts, programmes and books (The Teaching Company stuff, comedy shows, podcasts) while I'm traveling or just idling somewhere outside. But there's one major problem - PEOPLE SPEAK F-ING SLOW! So this is a script which speeds up the audio files for a better listening experience! Hope it's useful for someone!
#!/usr/bin/perl
my $file = shift;
sub speedupmp3 {
my $file = shift;
system("rm -rf audioPipe.wav");
system("mkfifo audioPipe.wav");
system("mplayer \"$file\" -ao pcm:file=audioPipe.wav -vc null -vo null -speed 1.6 -af scaletempo &");
system("lame -q 2 -b 64 audioPipe.wav \"$file.new\"");
`mkdir spedup`;
system("mv \"$file.new\" \"spedup/$file\"");
system("rm -rf audioPipe.wav");
}
if ($file eq "all") {
my @files = `find . -name \"*.mp3\" -maxdepth 1`;
#replace newlines and './' in the results of the find command with an empty string.
s/\n//g for @files;
s/\.\///g for @files;
speedupmp3($_) for @files;
} else {
speedupmp3($file);
}
I use mplayer from which I pipe directly to LAME via a named pipe (no intermediate wav files laying around).
Save as /usr/bin/speedupaudio for example and chmod +x it. You call it with a filename from the current dir as a parameter or with the parameter "all" which converts all .mp3 files in the current dir. The results are found in the directory ./spedup/
Offline
Not to knock the script or anything, but it seems like you have more system() calls than actual perl. Why not just use a bash script?
[git] | [AURpkgs] | [arch-games]
Offline
Yeah, I use Perl just to string my shell commands together and tie some logic to it. In theory it's better to use bash or even dash for that sort of thing, but I find bash if-structure/loop syntax too cryptic. Oh, hell, I'll admit it - I'm just too lazy to learn bash scripting properly. If someone wants to translate it to bash - that would be appreciated.
But when I wrote that the choices were - spend half an hour learning how to do the subroutine and if statement stuff in bash's syntax, or hack it in 5 minutes in something I already have some knowledge in, like Perl. For me, it's important that it does what it's meant to do.
Offline
yasen, I haven't tested this yet, but this shows how simple bash really can be.... your file, in bash as a function.
speedupmp3 ()
{
file="$1" ; rm -rf audioPipe.wav; mkfifo audioPipe.wav
mplayer "$file" -ao pcm:file=audioPipe.wav -vc null -vo null -speed 1.6 -af scaletempo &
lame -q 2 -b 64 audioPipe.wav "$file.new" ; mkdir spedup
mv "$file.new" "spedup/$file" ; rm -rf audioPipe.wav
}
If you put this into your .bashrc file, you now have your command at your fingertips when you need it.
source .bashrc one time if you don't want to open a new shell to use it the first time.
now, your command would be run with
speedupmp3 FILENAME
or if you want to do ALL the mp3's in the dir
speedupmp3 *.mp3
The funtion could simple be put into a bash script and called that way, but I like putting my functions into my .bashrc file, or some other file that's sourced into .bashrc or .profile so I can use it like a "normal" command line command.
Hope that's useful.
Last edited by crouse (2009-03-29 15:47:52)
Offline
It needs a file="$1" or for file in "$@"
[git] | [AURpkgs] | [arch-games]
Offline
It needs a file="$1" or for file in "$@"
yup, good catch, told you i hadn't tested it
Fixed.
Offline
Looks really good! Thanks
Offline
These might be useless and WAY simple seeing how I see some neat scripts in here but here it goes
abs-find: find the path to an abs package
#!/bin/sh
if [ $# -ne 1 ]
then
echo "Usage: `basename $0` [ ABS package name ]"
exit 0
else
find /var/abs -name "$1"
fi
abs-get: copies the supplied path directory into $HOME/build/abs (my abs directory)
#!/bin/sh
if [ $# -ne 1 ]
then
echo "Usage: `basename $0` [ ABS package path ]"
exit 0
else
cp -r "$1" $HOME/build/abs/`basename "$1"`
fi
ratinfo: I use Ratpoison WM and I have this binded to a key
#!/bin/sh
TEMP=$(cat /proc/acpi/thermal_zone/THRM/temperature | awk '{print $2"C"}')
FREQ=$(cpufreq-info | grep "current CPU frequency" | awk '{print $5"MHz"}')
DATE=$(echo -n $(date +%B,\ %d\ -\ %I:%M\ %p))
SDA1=$(df -h | grep /dev/sda1 |awk '{print $4"/"$2}')
SDA2=$(df -h | grep /dev/sda2 |awk '{print $4"/"$2}')
MPD=$(mpc | sed -n '1p')
INFO=$(echo -n "Arch $SDA1 :: Home $SDA2 :: CPUFreq: $FREQ :: Temperature $TEMP :: $MPD :: $DATE")
ratpoison -c "echo $INFO"
Wish I had more to post but I recently reinstalled and lost ALL my scripts in the move...
Last edited by Wra!th (2009-04-04 16:24:57)
MacGregor DESPITE THEM!
7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Offline
I made an function called kup that I use to upload images to kimag.es. It might already be posted in this thread, and I know for a fact that I have posted it elsewhere on these forums, but for the sake of completion I'm posting it here:
kup ()
{
curl -# -F userfile=@$1 http://kimag.es/index.php?action=upload|grep http://arch.kimag.es/share|cut -c112-150
}
[ lamy + pilot ] [ arch64 | wmii ] [ ati + amd ]
Offline
^^^ Oooh that is awesome!! I wonder how I could make that for Imageshack.us?? I tried simply replacing the URLs (I know, simple hehe) but while the upload seemed to work and progress to 100%, I didn't get anything for the link to the image.
Offline
this 1 checks the weather from the bbc site, then uses feh to change the wallpaper accordiingly. i have this set to run every hour in cron.
#!/bin/bash
curl http://feeds.bbc.co.uk/weather/feeds/rss/obs/world/0008.xml >/dev/null 2>&1 > .weatherfeedrs
##Set wallpaper depending on current conditions.
if grep -qw rain .weatherfeedrs ; then
feh --bg-scale /home/mark/weatherwallpapers/rain.jpg
elif grep -qw cloudy .weatherfeedrs ; then
feh --bg-scale /home/mark/weatherwallpapers/cloudy.jpg
elif grep -qw clear .weatherfeedrs ; then
feh --bg-scale /home/mark/weatherwallpapers/clear.jpg
elif grep -qw sunny .weatherfeedrs ; then
feh --bg-scale /home/mark/weatherwallpapers/sunny.jpg
else
echo other
fi
echo `date` `cat .weatherfeedrs | tail -n 13 | head -n 1 |cut -f1 -d'.'` >> ~/weatherhistory
there is probably a lot better way to do this, but this is working for me atm. i have it keep a list of previous weather stats, so i know what syntax bbc use, so i can update the greps accordingly .
Last edited by markp1989 (2009-04-04 21:44:48)
Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD
Offline
These might be useless and WAY simple seeing how I see some neat scripts in here but here it goes
abs-find: find the path to an abs package
#!/bin/sh if [ $# -ne 1 ] then echo "Usage: `basename $0` [ ABS package name ]" exit 0 else find /var/abs -name "$1" fi
abs-get: copies the supplied path directory into $HOME/build/abs (my abs directory)
#!/bin/sh if [ $# -ne 1 ] then echo "Usage: `basename $0` [ ABS package path ]" exit 0 else cp -r "$1" $HOME/build/abs/`basename "$1"` fi
ratinfo: I use Ratpoison WM and I have this binded to a key
#!/bin/sh TEMP=$(cat /proc/acpi/thermal_zone/THRM/temperature | awk '{print $2"C"}') FREQ=$(cpufreq-info | grep "current CPU frequency" | awk '{print $5"MHz"}') DATE=$(echo -n $(date +%B,\ %d\ -\ %I:%M\ %p)) SDA1=$(df -h | grep /dev/sda1 |awk '{print $4"/"$2}') SDA2=$(df -h | grep /dev/sda2 |awk '{print $4"/"$2}') MPD=$(mpc | sed -n '1p') INFO=$(echo -n "Arch $SDA1 :: Home $SDA2 :: CPUFreq: $FREQ :: Temperature $TEMP :: $MPD :: $DATE") ratpoison -c "echo $INFO"
Wish I had more to post but I recently reinstalled and lost ALL my scripts in the move...
nice, i will be using your abs-find script alot. very usefull thankyou:D
Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD
Offline
^^^ Oooh that is awesome!! I wonder how I could make that for Imageshack.us?? I tried simply replacing the URLs (I know, simple hehe) but while the upload seemed to work and progress to 100%, I didn't get anything for the link to the image.
You'll have to edit the grep parameters and the last command (cut -c112-150) to the acceptable values for imageshack.
[ lamy + pilot ] [ arch64 | wmii ] [ ati + amd ]
Offline
Thanks elmer_42, I will have to play around with that.
I'd like to add a function to my .bashrc that uses find (or another suitable process) to find files with a string, and copy the results to a folder. For example, I usually use "find -iname "*invoices*apr*" to find invoices for april, but I'd really like to be able to copy all the results instantly to another folder. Any help appreciated
Offline
Yup, but the find cmd I always use is "-iname "*string*"," like that.
Offline
i keep my music collection on shuffle in mpd. when a good song comes up i run this script with no options. after a few months of use, i have a nice little playlist that i can access via the same script with some other options listed in the help message. requires mpd/mpc and an at least mildly OCD tagging of your music collection. enjoy!
#!/bin/bash
#
# GoodSong V 0.1
#
# pbrisbin 2009
#
# keep a running list of good songs as they
# pop up in your playlist
#
# requires a mpd and mpc
#
###
# A place to keep the list
list="$HOME/.goodsongs"
# Get the now playing song from mpc and check
# if it's already in the list
song="$(mpc | head -n1)"
check=$(grep "$song" "$list")
# just the help message
message() {
echo ""
echo " GoodSong keeps a text file of good songs pulled from"
echo " mpd. When run with no options, it simply appends the"
echo " currently mpd playing song to the list. other"
echo " options are as follows:"
echo ""
echo " -s | --show Displays a random song from the"
echo " existing list."
echo ""
echo " -p | --play Plays a random song from the"
echo " existing list."
echo ""
echo " -b | --build Builds a playlist of your full"
echo " existing list."
echo ""
echo " -h | --help Displays this message and quits."
echo ""
exit 1
}
# get the filename from a line in the list
getfilename() {
artist="$(echo $1 | sed 's/\ \-\ /+/g' | cut -d "+" -f 1)"
title="$(echo $1 | sed 's/\ \-\ /+/g' | cut -d "+" -f 2)"
filename="$(mpc search artist "$artist" title "$title" | head -n1)"
}
# create it if it doesn't exist
[ -f $list ] || touch $list
# parse the CLI options if they're there
case $1 in
-h|--help)
message
;;
-s|--show)
track="$(cat $list | sort -R | head -n1)"
echo $track
;;
-p|--play)
track="$(cat $list | sort -R | head -n1)"
getfilename "$track"
mpc clear
mpc add "$filename"
mpc play
;;
-b|--build)
mpc clear
cat $list | while read track; do
getfilename "$track"
echo $filename
done
mpc play
;;
*)
[ -z "$check" ] && echo "$song" >> "$list"
echo "Added \"$song\" to the list. try -h for more options."
;;
esac
exit 0
may break if you have the string " - " anywhere in an artist or title tag
edit: quick bugfix, i'll probably do that a few times...
Last edited by brisbin33 (2009-04-07 16:00:12)
//github/
Offline
i keep my music collection on shuffle in mpd. when a good song comes up i run this script with no options. after a few months of use, i have a nice little playlist that i can access via the same script with some other options listed in the help message. requires mpd/mpc and an at least mildly OCD tagging of your music collection. enjoy!
#!/bin/bash # # GoodSong V 0.1 # # pbrisbin 2009 # # keep a running list of good songs as they # pop up in your playlist # # requires a mpd and mpc # ### # A place to keep the list list="$HOME/.goodsongs" # Get the now playing song from mpc and check # if it's already in the list song="$(mpc | head -n1)" check=$(grep "$song" "$list") # just the help message message() { echo "" echo " GoodSong keeps a text file of good songs pulled from" echo " mpd. When run with no options, it simply appends the" echo " currently mpd playing song to the list. other" echo " options are as follows:" echo "" echo " -s | --show Displays a random song from the" echo " existing list." echo "" echo " -p | --play Plays a random song from the" echo " existing list." echo "" echo " -b | --build Builds a playlist of your full" echo " existing list." echo "" echo " -h | --help Displays this message and quits." echo "" exit 1 } # get the filename from a line in the list getfilename() { artist="$(echo $1 | sed 's/\ \-\ /+/g' | cut -d "+" -f 1)" title="$(echo $1 | sed 's/\ \-\ /+/g' | cut -d "+" -f 2)" filename="$(mpc search artist "$artist" title "$title" | head -n1)" } # create it if it doesn't exist [ -f $list ] || touch $list # parse the CLI options if they're there case $1 in -h|--help) message ;; -s|--show) track="$(cat $list | sort -R | head -n1)" echo $track ;; -p|--play) track="$(cat $list | sort -R | head -n1)" getfilename "$track" mpc clear mpc add "$filename" mpc play ;; -b|--build) mpc clear cat $list | while read track; do getfilename "$track" echo $filename done mpc play ;; *) [ -z "$check" ] && echo "$song" >> "$list" echo "Added \"$song\" to the list. try -h for more options." ;; esac exit 0
may break if you have the string " - " anywhere in an artist or title tag
edit: quick bugfix, i'll probably do that a few times...
that seems pretty cool, would be nice if you could use this kind of thing for smart shuffle.
im just about to go out, but wehn im back i will prob tie this to 1 of my spare keys , Thanks
considering that all of my songs are properly taged, i havnt got to do alot of work.
Last edited by markp1989 (2009-04-07 17:27:01)
Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD
Offline
Just wrote a shutdown/suspend etc. confirmation script for openbox, probably been done before (and better), but i like it, and it works (it requires zenity btw):
#!/bin/bash
# Warning dialogue box for an exit action (passed as an argument)
# kourosh - 7/04/2009
#Determine arguments and what action to take
case $1 in
Shutdown)
ACTION="sudo poweroff";
;;
Suspend)
ACTION="sudo pm-suspend";
;;
Hibernate)
ACTION="sudo pm-hibernate";
;;
Reboot)
ACTION="sudo reboot";
;;
*)
zenity --error --text="Usage: exit.sh [options] \n \n Options: \n Shutdown \n Suspend \n Hibernate \n Reboot \n"
exit 0
;;
esac
#Ask the question
zenity --question \
--text="Are you sure you want to $1?" \
--title=$1 \
--ok-label=$1 \
;echo $? > /tmp/test #Have to send this to a temp file for some reason
#Either do the job or exit, remove temp files while you're at it
if [ $(cat /tmp/test) = "0" ]; then
rm /tmp/test
`$ACTION`
else
rm /tmp/test
exit 0
fi
Last edited by kourosh (2009-04-07 22:34:26)
Offline
dmenu application launcher, with your most used applications listed first and you can append a ";" to start the program in a terminal.
#!/bin/sh
DMENU="dmenu -i"
TERMI="urxvt -e"
CACHE="$HOME/.dmenu_cache_recent"
touch $CACHE
MOST_USED=`sort $CACHE | uniq -c | sort -r | colrm 1 8`
RUN=`(echo "$MOST_USED"; dmenu_path | grep -vxF "$MOST_USED") | $DMENU` &&
(echo $RUN; head -n 99 $CACHE) > $CACHE.$$ &&
mv $CACHE.$$ $CACHE
case $RUN in
*\;) exec `echo $TERMI $RUN | sed -e 's/;$//'`;;
*) exec $RUN;;
esac
Returns a random file from the directory given.
#!/bin/sh
echo `find $1 -type f |
awk 'BEGIN{
srand()
}
{
names[NR]=$0
}
END{
i=1+int(rand()*NR)
print names[i]
}
'`
Offline