(追記) (追記ここまで)

Commands using sed (1,321)
sorted by

  • Usage: translate <phrase> <source-language> <output-language> Example: translate hello en es See this for a list of language codes: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

    This is sample output - yours may be different.
    hola

    67
    translate(){ wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=1ドル&langpair=2ドル|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/1円\n/'; }
    matthewbauer · 2010年03月08日 03:15:48 203
  • Prints a graphical directory tree from your current directory

    This is sample output - yours may be different.
    |-Comics
     |---Anomaly
     |---Cyanide & Happiness
     |---Dilbert
     |---Misc
     |---Pearls Before Swine
     |---Russell's Teapot
     |---xkcd
     |-Docks
     |---Niqu Dock 1.2
     |-----2D Style
     |-----3D Style
     |-----Defaults
     |---Rounded Reflection
     |-Ebooks
     |---The Guitarist's Guide to Composing and Improvising

    64
    ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
    unixmonkey842 · 2009年02月15日 20:43:21 33
  • This is the result of a several week venture without X. I found myself totally happy without X (and by extension without flash) and was able to do just about anything but watch YouTube videos... so this a the solution I came up with for that. I am sure this can be done better but this does indeed work... and tends to work far better than YouTube's ghetto proprietary flash player ;-) Replace $i with any YouTube ID you want and this will scrape the site for the _real_ URL to the full quality .FLV file on Youtube's server and will then will hand that over to mplayer (or vlc or whatever you want) to be streamed. In some browsers you can replace $i with just a % or put this in a shell script so all YouTube IDs can be handed directly off to your media player of choice for true streaming without the need for Flash or a downloader like clive. (I do however fully recommend clive if you wish to archive videos instead of streaming them) If any interest is shown I would be more than happy to provide similar commands for other sites. Most streaming flash players use similar logic to YouTube. Edit: 05/03/2011 - Updated line to work with current YouTube. It could be a lot prettier but I will probably follow up with another update when I figure out how to get rid of that pesky Grep. Sed should take that syntax... but it doesn't. Original (no longer working) command: mplayer -fs $(echo "http://youtube.com/get_video.php?$(curl -s $youtube_url | sed -n "/watch_fullscreen/s;.*\(video_id.\+\)&title.*;1円;p")")

    This is sample output - yours may be different.
    MPlayer SVN-r32999-4.4.5 (C) 2000-2011 MPlayer Team
    Playing http://v3.lscache2.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor&fexp=901031%2C907508%2C900304&algorithm=throttle-factor&itag=34&ipbits=8&burst=40&sver=3&signature=97D6F8D1A948EF2451FD4F093ECA7EF3795EE424.73F2B07D5F478ACEAFCEAC98E7BF2623FEED20EC&expire=1299384000&key=yt1&ip=97.0.0.0&factor=1.25&id=f2ecb156675a27ec.
    Resolving v3.lscache2.c.youtube.com for AF_INET6...
    Couldn't resolve name for AF_INET6: v3.lscache2.c.youtube.com
    Resolving v3.lscache2.c.youtube.com for AF_INET...
    Connecting to server v3.lscache2.c.youtube.com[74.125.15.14]: 80...
    Cache size set to 320 KBytes
    Cache fill: 19.54% (64036 bytes) 
    libavformat file format detected.
    [flv @ 0x2acf540] Estimating duration from bitrate, this may be inaccurate
    [lavf] stream 0: video (h264), -vid 0
    [lavf] stream 1: audio (aac), -aid 0
    VIDEO: [H264] 640x360 0bpp 24.000 fps 557.2 kbps (68.0 kbyte/s)
    Clip info:
     duration: 162
     starttime: 0
     totalduration: 162
     width: 640
     height: 360
     videodatarate: 544
     audiodatarate: 97
     totaldatarate: 649
     framerate: 24
     bytelength: 13120260
     canseekontime: true
     sourcedata: B4A7D0F03HH1299359484777471
     purl: 
     pmsg: 
    ==========================================================================
    Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
    Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
    ==========================================================================
    ==========================================================================
    Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
    AUDIO: 44100 Hz, 2 ch, s16le, 99.0 kbit/7.02% (ratio: 12379->176400)
    Selected audio codec: [ffaac] afm: ffmpeg (FFmpeg AAC (MPEG-2/MPEG-4 Audio))
    ==========================================================================
    [AO OSS] audio_setup: Can't open audio device /dev/dsp: Device or resource busy
    AO: [alsa] 44100Hz 2ch s16le (2 bytes per sample)
    Starting playback...
    Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
    VO: [xv] 640x360 => 640x360 Planar YV12 [fs]
    A: 2.4 V: 2.4 A-V: -0.000 ct: 0.000 0/ 0 19% 15% 0.4% 7 0 47% 
    

    58
    i="8uyxVmdaJ-w";mplayer -fs $(curl -s "http://www.youtube.com/get_video_info?&video_id=$i" | echo -e $(sed 's/%/\\x/g;s/.*\(v[0-9]\.lscache.*\)/http:\/\/1円/g') | grep -oP '^[^|,]*')
    lrvick · 2009年03月09日 03:57:44 75
  • Checks the Gmail ATOM feed for your account, parses it and outputs a list of unread messages. For some reason sed gets stuck on OS X, so here's a Perl version for the Mac: curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*<name>(.*)<\/name>.*$/2ドル - 1ドル/' If you want to see the name of the last person, who added a message to the conversation, change the greediness of the operators like this: curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*?<name>(.*?)<\/name>.*$/2ドル - 1ドル/'

    This is sample output - yours may be different.
    Contact Name - Email Subject
    Contact Name2 - Email Subject2
    (...)

    47
    curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/2円 - 1円/p"
    postrational · 2009年09月07日 21:56:40 62
  • You can get one specific line during any procedure. Very interesting to be used when you know what line you want.

    This is sample output - yours may be different.
    jeju:[xxx] > sed -n 5p test
    line 5
    jeju:[xxx] > cat test
    line 1
    line 2
    line 3
    line 4
    line 5
    line 6
    line 7
    line 8
    line 9
    line 10
    jeju:[xxx] >

    44
    sed -n 5p <file>
    Waldirio · 2009年10月15日 11:00:48 143
  • Nothing special required, just wget, sed & tr!

    This is sample output - yours may be different.
    Resolving v3.lscache3.c.youtube.com... 74.125.170.46
    Connecting to v3.lscache3.c.youtube.com|74.125.170.46|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 25120289 (24M) [video/x-flv]
    Saving to: `surprise.flv'

    36
    wget http://www.youtube.com/watch?v=dQw4w9WgXcQ -qO- | sed -n "/fmt_url_map/{s/[\'\"\|]/\n/g;p}" | sed -n '/^fmt_url_map/,/videoplayback/p' | sed -e :a -e '$q;N;5,$D;ba' | tr -d '\n' | sed -e 's/\(.*\),\(.\)\{1,3\}/1円/' | wget -i - -O surprise.flv
    Eno · 2011年01月25日 04:19:06 25
  • This is sample output - yours may be different.

    30
    sed -i 8d ~/.ssh/known_hosts
    prayer · 2010年07月10日 14:22:34 13
  • (relies on 'imagemagick') This command will convert all .pdf files in a directory into a 800px (wide or height, whichever is smaller) image (with the aspect ratio kept) .jpg. If the file is named 'example1.pdf' it will be named 'example1.jpg' when it is complete. This is a VERY worthwhile command! People pay hundreds of dollars for this in the Windows world. My .jpg files average between 150kB to 300kB, but your's may differ.

    This is sample output - yours may be different.
    for file in `ls *.pdf`; do convert -verbose -colorspace RGB -resize 800 -interlace none -density 300 -quality 80 $file `echo $file | sed 's/\.pdf$/\.jpg/'`; done
    "gs" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r300x300" "-sOutputFile=/tmp/magick-XXz6cMMo" "-f/tmp/magick-XX9DNL7g" "-f/tmp/magick-XXPGU3s9"

    29
    for file in `ls *.pdf`; do convert -verbose -colorspace RGB -resize 800 -interlace none -density 300 -quality 80 $file `echo $file | sed 's/\.pdf$/\.jpg/'`; done
    brettalton · 2009年02月15日 23:27:43 26
  • Sed stops parsing at the match and so is much more effecient than piping head into tail or similar. Grab a line range using sed '999995,1000005!d' < my_massive_file

    This is sample output - yours may be different.

    26
    sed '1000000!d;q' < massive-log-file.log
    root · 2009年01月26日 11:50:00 2798
  • recursively traverse the directory structure from . down, look for string "oldstring" in all files, and replace it with "newstring", wherever found also: grep -rl oldstring . |xargs perl -pi~ -e 's/oldstring/newstring'

    This is sample output - yours may be different.

    25
    $ grep -rl oldstring . |xargs sed -i -e 's/oldstring/newstring/'
    netfortius · 2009年03月03日 20:10:19 37
  • This is sample output - yours may be different.

    24
    sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
    Cowboy · 2009年09月23日 12:06:33 286
  • If you have used bash for any scripting, you've used the date command alot. It's perfect for using as a way to create filename's dynamically within aliases,functions, and commands like below.. This is actually an update to my first alias, since a few commenters (below) had good observations on what was wrong with my first command. # creating a date-based ssh-key for askapache.github.com ssh-keygen -f ~/.ssh/`date +git-$USER@$HOSTNAME-%m-%d-%g` -C 'webmaster@askapache.com' # /home/gpl/.ssh/git-gplnet@askapache.github.com-04-22-10 # create a tar+gzip backup of the current directory tar -czf $(date +$HOME/.backups/%m-%d-%g-%R-`sed -u 's/\//#/g' <<< $PWD`.tgz) . # tar -czf /home/gpl/.backups/04-22-10-01:13-#home#gpl#.rr#src.tgz . I personally find myself having to reference date --help quite a bit as a result. So this nice alias saves me a lot of time. This is one bdash mofo. Works in sh and bash (posix), but will likely need to be changed for other shells due to the parameter substitution going on.. Just extend the sed command, I prefer sed to pretty much everything anyways.. but it's always preferable to put in the extra effort to go for as much builtin use as you can. Otherwise it's not a top one-liner, it's a lazyboy recliner. Here's the old version: alias dateh='date --help|sed "/^ *%%/,/^ *%Z/!d;s/ \+/ /g"|while read l;do date "+ %${l/% */}_${l/% */}_${l#* }";done|column -s_ -t' This trick from my [ http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html bash_profile ]

    This is sample output - yours may be different.
    %%: '%' a literal %
    %a: 'Wed' locale's abbreviated weekday name (e.g., Sun)
    %A: 'Wednesday' locale's full weekday name (e.g., Sunday)
    %b: 'Mar' locale's abbreviated month name (e.g., Jan)
    %B: 'March' locale's full month name (e.g., January)
    %c: 'Wed Mar 27 23:50:06 2013' locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
    %C: '20' century; like 2013, except omit last two digits (e.g., 20)
    %d: '27' day of month (e.g., 01)
    %D: '03/27/13' date; same as 03/27/13
    %e: '27' day of month, space padded; same as 27
    %F: '2013-03-27' full date; same as 2013年03月27日
    %g: '13' last two digits of year of ISO week number (see 2013)
    %G: '2013' year of ISO week number (see 13); normally useful only with 13
    %h: 'Mar' same as Mar
    %H: '23' hour (00..23)
    %I: '11' hour (01..12)
    %j: '086' day of year (001..366)
    %k: '23' hour, space padded ( 0..23); same as 23
    %l: '11' hour, space padded ( 1..12); same as 11
    %m: '03' month (01..12)
    %M: '50' minute (00..59)
    %n: ' ' a newline
    %N: '853525313' nanoseconds (000000000..999999999)
    %p: 'PM' locale's equivalent of either AM or PM; blank if not known
    %P: 'pm' like PM, but lower case
    %r: '11:50:06 PM' locale's 12-hour clock time (e.g., 11:11:04 PM)
    %R: '23:50' 24-hour hour and minute; same as 23:50
    %s: '1364442606' seconds since 1970年01月01日 00:00:00 UTC
    %S: '06' second (00..60)
    %t: ' ' a tab
    %T: '23:50:06' time; same as 23:50:06
    %u: '3' day of week (1..7); 1 is Monday
    %U: '12' week number of year, with Sunday as first day of week (00..53)
    %V: '13' ISO week number, with Monday as first day of week (01..53)
    %w: '3' day of week (0..6); 0 is Sunday
    %W: '12' week number of year, with Monday as first day of week (00..53)
    %x: '03/27/13' locale's date representation (e.g., 12/31/99)
    %X: '23:50:06' locale's time representation (e.g., 23:13:48)
    %y: '13' last two digits of year (00..99)
    %Y: '2013' year
    %z: '-0400' +hhmm numeric time zone (e.g., -0400)
    %:z: '-04:00' +hh:mm numeric time zone (e.g., -04:00)
    %::z: '-04:00:00' +hh:mm:ss numeric time zone (e.g., -04:00:00)
    %:::z: '-04' numeric time zone with : to necessary precision (e.g., -04, +05:30)
    %Z: 'EDT' alphabetic time zone abbreviation (e.g., EDT)
    

    21
    alias dateh='date --help|sed -n "/^ *%%/,/^ *%Z/p"|while read l;do F=${l/% */}; date +%$F:"|'"'"'${F//%n/ }'"'"'|${l#* }";done|sed "s/\ *|\ */|/g" |column -s "|" -t'
    AskApache · 2010年04月21日 01:22:18 17
  • Use sed to color the output of a human-readable dmesg output

    This is sample output - yours may be different.

    21
    dmesg -T|sed -e 's|\(^.*'`date +%Y`']\)\(.*\)|\x1b[0;34m1円\x1b[0m - 2円|g'
    jlaunay · 2012年07月31日 22:21:07 61
  • Delete a range of line

    This is sample output - yours may be different.

    19
    sed -i <file> -re '<start>,<end>d'
    Zulu · 2012年02月02日 17:59:18 44
  • Original author unknown (I believe off of a wifi hacking forum). Used in conjuction with ifconfig and cron.. can be handy (especially spoofing AP's)

    This is sample output - yours may be different.
    00:12:2F:22:32:16

    17
    MAC=`(date; cat /proc/interrupts) | md5sum | sed -r 's/^(.{10}).*$/1円/; s/([0-9a-f]{2})/1円:/g; s/:$//;'`
    vaporub · 2009年02月16日 07:09:43 119
  • This is sample output - yours may be different.

    16
    sed 's/\o0/\n/g' /proc/INSERT_PID_HERE/environ
    unixmonkey3402 · 2009年04月23日 22:58:57 86
  • This command find all files in the current dir and subdirs, and replace all occurances of "oldstring" in every file with "newstring".

    This is sample output - yours may be different.

    16
    find . -type f -exec sed -i s/oldstring/newstring/g {} +
    SlimG · 2009年12月09日 00:46:13 31
  • Use the following variation for FreeBSD: openssl rand 6 | xxd -p | sed 's/\(..\)/1円:/g; s/:$//'

    This is sample output - yours may be different.

    16
    openssl rand -hex 6 | sed 's/\(..\)/1円:/g; s/.$//'
    putnamhill · 2010年09月23日 02:31:12 6
  • This is sample output - yours may be different.

    16
    check(){ curl -sI 1ドル | sed -n 's/Location: *//p';}
    putnamhill · 2010年09月30日 12:29:02 40
  • Just another curl command to get your public facing IP

    This is sample output - yours may be different.
    123.456.789.000

    14
    curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z<>/ :]//g'
    vaporub · 2009年02月16日 07:12:01 99
  • This is sample output - yours may be different.

    14
    sed -i 8d ~/.ssh/known_hosts
    prayer · 2009年03月03日 01:13:28 18
  • echo "http%3A%2F%2Fwww.google.com" | sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x1円/g' | xargs echo -e http://www.google.com Works under bash on linux. just alter the '-e' option to its corresponding equivalence in your system to execute escape characters correctly.

    This is sample output - yours may be different.

    14
    sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x1円/g' | xargs echo -e
    mohan43u · 2009年05月25日 05:37:44 52
  • This is sample output - yours may be different.

    14
    curl -s https://api.github.com/users/<username>/repos?per_page=1000 |grep git_url |awk '{print 2ドル}'| sed 's/"\(.*\)",/1円/'
    wuseman1 · 2019年11月19日 20:31:19 783
  • This one uses dictionary.com

    This is sample output - yours may be different.

    13
    pronounce(){ wget -qO- $(wget -qO- "http://dictionary.reference.com/browse/$@" | grep 'soundUrl' | head -n 1 | sed 's|.*soundUrl=\([^&]*\)&.*|1円|' | sed 's/%3A/:/g;s/%2F/\//g') | mpg123 -; }
    matthewbauer · 2010年03月13日 04:23:56 15
  • Though without infinite time and knowledge of how the site will be designed in the future this may stop working, it still will serve as a simple straight forward starting point. This uses the observation that the only item marked as strong on the page is the single logical line that includes the italicized fact. If future revisions of the page show failure, or intermittent failure, one may simply alter the above to read. wget randomfunfacts.com -O - 2>/dev/null | tee lastfact | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;1円;" The file lastfact, can then be examined whenever the command fails.

    This is sample output - yours may be different.

    13
    wget randomfunfacts.com -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;1円;"
    tali713 · 2010年03月30日 23:49:30 86
  • 1 2 3 > Last ›

What's this?

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.

Share Your Commands


Check These Out

Trace python statement execution and syscalls invoked during that simultaneously

delete file name space the rename is rename perl version

Once you get into advanced/optimized scripts, functions, or cli usage, you will use the sort command alot. The options are difficult to master/memorize however, and when you use sort commands as much as I do (some examples below), it's useful to have the help available with a simple alias. I love this alias as I never seem to remember all the options for sort, and I use sort like crazy (much better than uniq for example). # Sorts by file permissions $ find . -maxdepth 1 -printf '%.5m %10M %p\n' | sort -k1 -r -g -bS 20% 00761 drwxrw---x ./tmp 00755 drwxr-xr-x . 00701 drwx-----x ./askapache-m 00644 -rw-r--r-- ./.htaccess # Shows uniq history fast $ history 1000 | sed 's/^[0-9 ]*//' | sort -fubdS 50% exec bash -lxv export TERM=putty-256color Taken from my http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html

just use a space to prevent commands from being recorded in bash's history on most systems

Replace the with your URL, for example http://rublacklist.net/12348/ and it will show likes number

The simplest way to do it. Works for me, at least. (Why are the variables being set?)

swap out "80" for your port of interest. Can use port number or named ports e.g. "http"


Stay in the loop…

Follow the Tweets.

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

Subscribe to the feeds.

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:

AltStyle によって変換されたページ (->オリジナル) /