ACPI administration advocacy advocacy advocacy opinion alsa amarok apache apple apt aptitude archive audio audo authentication automount avi awk backup bash BIOS boot browser business bzip cache calendar calibre cdr cdrecord censorship commandline computerscience console convert cron cut database date debian degree design desktop development disk dpkg dvd economics education emacs email europe exim faad ffmpeg file files firefox firewall flash foss freedom ftp fun fuse git gnumeric graphics grep growisofs grub gtkpod gzip hardware hardware html icedove idiocy image imagemagick images installation ip iphone ipod iptables iso itunes ivman kde kernel keyboard knoppix lame laptop latex libreoffice linux locale lockin locking longlines lsof m4a microsoft mimetypes minitab mogrify mount mp3 mp4 mplayer multimedia music mysql network nfs nfs4 nmap openbox openfiles openoffice opinion opinion orgmode partition pdf pdftk perl php podcast politics pomodoro ports postgresql print printing privacy process programming rant remote rhythmbox rss rsync rxvt scp screengrab screenshot script scripting scsi security sed server services shell siteadmin sitenews sitesoftware skype skype slackware sound sox spam spreadsheet ssh statistics subversion sudo svk swap t23 t43 tar terminal tex text thinkpad thunderbird time timer timezone ubuntu udev upgrade usb usbmount users uuid versioncontrol vfat video vnc windows wine wordpress wordprocessing X40 xwindows xwindows youtube
Recently, I had a text file that I had created by using pdf2text - it's a great way to get data out of pdfs into a useful format. Anyway, the data ended up being in "filename.txt" the form:
2 Peter 7 Alice 5 Fred
I needed it sorted. But how? The "sort" command came ot the rescue. Typing this:
Gave this output:
2 Peter 5 Fred 7 Alice
However, I wanted it sorted on the second field, that is the names. "sort" can do this too:
sort -d -k 2 filename.txt
Brief explanation: The '-d' switch stands for 'dictionary sort' and ensures that sorting takes place alphabetically as a dictionary would do it. The '-k' switch stands for 'key' and with the '2' tells sort to sort on the second field in the file, that is the names. The fields themselves are separated by spaces.
how would you sort on the second field in the case that the text file was like this: 2Peter 7Alice 5Fred
Hohw would you tell the sort command to sort on second field?