AIX Tip of the Week: UNIX "join" Command

Audience: AIX Users Date: December 1998

A little known, but useful, UNIX data manipulation tool is the join command. The function of the join command is si join. It combines common lines from two sorted text files based on a common field. The output of the join command remainder of each line from both files. Unmatched lines are not included in the output.

The following example illustrates the use of the join command. In this example, a hypothetical inventory file is joined on the part number. The inventory file is a two column file containing a list of part numbers and its quantity on hand. column file containing the part number and its description. The common field between the two files is the part numbe the part number.

Example
$ cat description.txt Part Number; Description 1; Pencils 2; Erasers 3; Paper Clips, Regular 3A; Paper Clips, Large 4; Paper, Regular 8.5x11 4A; Paper, Legal Size 5; Envelope 6; Staples 7; Tape 8; Hole Punch 9; Glue 10; Pen, Blue 10A; Pen, Red 10B; Pen, Black 10C; Pen, Green ....etc... $ cat inventory.txt Part Number; Quantity on Hand 1; 4 3; 16 3A; 24 4; 0 6; 1 8; 8 10; 2 10B; 14 ....etc.... $ join -t";" inventory.txt description.txt Part Number; Quantity on Hand; Description 1; 4; Pencil 3; 16; Paper Clips, Regular 3A; 24; Paper Clips, Large 4; 0; Paper, Regular 8.5x11

6; 8; 10; 10B; ....etc....

1; 8; 2; 14;

Staples Hole Punch Pen, Blue Pen, Black

Note that only the matching lines are displayed. Unmatched lines are discarded. See the man page for the join comma

AIX Tip of the Week: Accesing Remote Tape Drives
Audience: AIX Users and Administrators Date: April 1999

One of the advantages of UNIX is the ability to share remote devices, such as tape drives. The "rdump/rrestore" comm backup/restore files to a tape drive on a remote system. However, because these commands require a ".rhost" file, ma security exposure.

One alternative is to use the more secure "rexec" command which prompts for a user id/password. The following exam "rexec" command to access remote tape drives. In this example, the "tape_host" is the TCP-IP hostname of the system "data_host" is the system where the files reside. The example also assumes you have a valid user id/password on both To create a backup to a remote system with a tape, issue the following command from the "data_host." tar -cvf - * | dd bs=1k | rexec tape_host "dd bs=1k of=/dev/rmt0" To restore this tape, issue the following command from the "tape_host" system. dd bs=1k if=/dev/rmt0 | rexec data_host "dd bs=1k | tar -xvf-" The general concept illustrated above can be extended to other remote devices such as diskettes, CD-ROMs and disk

AIX Tip of the Week: Using an RS/6000 System with a Graphics Display as an "X" Terminal
Audience: AIX Users Date: May 7, 1999

Any RS/6000 with a graphics terminal can be used as an "X" terminal**. An "X" terminal functions as a graphics dis a TCP/IP network. The following command starts a CDE session from a remote host on a local graphics display: X -query "remote_host_name"

Where "remote_host_name" is the TCP/IP name of the remote host. To run this command, you must be logged into th

Refer t more information. bold. Audience: AIX Administrators and End Users Date: November 12. My tests indicate that this command may fail on systems with multiple network adapters. reverse. IBM # tput commands to control highlighting # note: some terminals do not support all tput options RVR=`tput smso` # reverse END_RVR=`tput rmso` # end reverse BLNK=`tput blink` # blink UNDER=`tput smul` # underline END_UNDER=`tput rmul` # underline CLEAR=`tput clear` # clear screen BELL=`tput bel` # bell sound BOLD=`tput bold` # bold DIM=`tput dim` # dim INVIS=`tput invis` # invisible END=`tput sgr0` # turn off dim. use the "tput" command. IB Comments: 1. but xdm may/may not be installed depending on the AIX. #!/usr/bin/ksh # Script Name: today # v1. as July 1999 Sun Mon Tue Wed Thu 1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29 Fri 2 9 16 23 30 Sat 3 10 17 24 31 ** Depends on the terminal's capability. invisible .display in the command line mode. Prerequisites: X11 and xdm software must be installed on both hosts.0 Calendar with today's date highlighted # Bruce Spencer. The following keystroke combination terminates the session: Ctrl-Alt-Backspace This command should work for any combination of UNIX systems that support X11 and XDM. including Sun. To highlight text on sessions. underl The attached "today" script uses the "tput" command to highlight today's date in the output of the "cal" command. 2. 1999 Highlighting text on computer terminals is useful for drawing attention to important information. Both are included int the AIX base CD-R by default. Some ASCII terminals/emulators don't support all of the tput options. bold. blink. dim. The types of highting available with "tput" includes blinking. HP.

Apr) MONTH=4.. To save typing. put this command in a s #!/usr/bin/ksh # Script name: locate find . Another variation would be to "searchstring" with another string by changing the "grep" to "sed" command.... type locate searchstring.. esac DAY=`echo ${3} | sed "s/^0//"` cal $MONTH ${6} | sed "s/ ${DAY}/ ${RVR}${DAY}${END_RVR}/" # # # # # # # Examples of different formatting echo "${UNDER}Underline: Happy Thanksgiving!${END_UNDER}" echo "${BOLD}Bold: Happy Thanksgiving!${END}" echo "${DIM}Dim: Happy Thanksgiving!${END}" echo "${BELL}BELL: Happy Thanksgiving!${END}" echo "${INVIS}Invisible: Happy Thanksgiving!${END}" echo "${BLINK}Blink: Happy Thanksgiving!${END}" Finding Files Containing a String Audience: AIX Administrators Date: December 10. Nov) MONTH=11.. Jul) MONTH=7. -type f -print | xargs -i grep -il "searchstring" {} where: "searchstring" is the desired search string "find . Jun) MONTH=6. -type f -print" lists all files in the current directory and it subdirectories "xargs" feeds the file names from the pipe into the grep command at the curly braces {} The "grep -il" lists the files containing the "searchstring" (-i = case insensitive) I use this command to find files on a web site that contain references to specific URL... Feb) MONTH=2. where searchstring" is the name of the search string.# Clear Screen echo ${CLEAR} # Convert month abbreviation to month number set `date` case ${2} in Jan) MONTH=1. Aug) MONTH=8. *) MONTH=0.. . Mar) MONTH=3... May) MONTH=5. Dec) MONTH=12. find . -type f -print | xargs -i grep -il "$1" {} To run. 1999 Here's a useful technique for searching for files in all subdirectories which contain a specific string.. Sep) MONTH=9.. Oct) MONTH=10.

executables. "wait" command works: #!/usr/bin/ksh a & b & wait c Jobs "a" and "b" are started in the background (&).Working with Diskettes in AIX Audience: AIX Users Date: January 7. 2000 Three useful Korn shell commands for controlling job flow based on the outcome of other processes are &&. However. the wait command can be directed to wa to the man pages for more information. 2000 The find / -mtime -nn -ls command can be used to identify files that have changed within the past "nn" days. Howe . The "wait" command waits for both "a" and "b" to complete befor the wait command waits for all background processes to complete. Diskette Format PC DOS Command to View Diskette dosdir -l Comments Part of the "bos. || and w a && b a || b wait # run "b" if "a" completes successfully # run "b" if "a" fails # wait for completion of one or more background jobs to complete before p In the above examples. 2000 The following is a list of the most common commands for reading floppy diskettes in AIX. "a". shell scripts.d Related comman dosformat Unix Unix Unix tar -tvf /dev/rfd0 restore -Tvq cpio -itv </dev/rfd0 Diskettes created command AIX Tip of the Week: Korn Shell Job Control Audience: AIX Administrators and End Users Date: February 4. "b" and "c" can be UNIX commands. or combinations thereof. AIX Tip of the Week: Locating Recently Modified AIX Files Audience: AIX Administrators and End Users Date: February 11.

files that have changed in the past 24 hours. and "-type" by type of file. See the AIX man p The following Korn shell script illustrates the use of these commands. "-user" for locating file by user. or files that are filling up a directory. then using the find command's "-newer" flag to locate the files. touch -t mmddhhmm touched_file find / -newer touched_file -ls Where: • • • • • touched_file is any file name you choose mm is month dd is day hh is hour (24 hour format) mm is minute This trick is useful for finding log files with new entries. #!/usr/bin/ksh # Purpose: identify files starting in the current directory # that have changed *today* within the past nn hours # You'll have to modify this script to work around midnight # Bruce Spencer. The trick involves creating an empty the end of the desired time frame. Other useful find optio identifying files larger than nn blocks. IBM 2/11/00 USAGE="Usage: $0 n \t\t\t# where n= 1-24 hours" # check for syntax errors if [[ $# -ne 1 ]] then echo $USAGE exit 1 fi if [[ $1 -gt 24 ]] then echo $USAGE exit 1 fi HH=$(date +%H) if [[ $1 -gt $HH ]] then echo "Error: The requested time span $1 is greater than current time $HH" exit 1 fi # Passed checks let hh=HH-$1 if [[ $hh -lt 10 ]] then #hours must be two digits timestamp="$(date +%m%d)0${hh}00" else timestamp="$(date +%m%d)${hh}00" . Here's a trick to identify these files.

. Quit) exit.. ListActiveUsers) who. -xdev -type file -newer $touch_file -ls rm $touch_file AIX Tip of the Week: Using the Korn Shell select to Create Selection Menu's Audience: AIX Administrators and End Users Date: May 11... ManageDatabase) svrmgr. 2000 The Korn shell select command can be used to create a selection menu. MonitorPerformance) topas. *) echo "\nInvalid Choice\n". esac done .Spencer 5/11/00 echo "XYZ Operator Console" echo # PS3 is an environment variable # that sets the menu prompt PS3="Choose a number: " # The select command creates the menu select CHOICE in SystemBackup ListActiveUsers ManageDatabase MonitorPerformance Quit do case $CHOICE in SystemBackup) mksysb -i /dev/rmt0.. the attached shell script generate for a hypothetical operator console: XYZ Operator Console 1) 2) 3) 4) 5) SystemBackup ListActiveUsers ManageDatabase MonitorPerformance Quit Choose a number: Korn Shell Script that Creates Above Menu #!/usr/bin/ksh # Shell script to illustrate the use of # the Korn shell "select" command # to create selection menus # B. To illustrate.fi # Create a "touch file" in /tmp to avoid write permissions problem touch_file="/tmp/${LOGNAME}junk" touch -t $timestamp $touch_file find ..

3.pl Perl is standard in AIX 4.3. 2000 One way to capture the results of multiple commands in a file would be: cmd1 > $results cmd2 >> $results : cmdN >> $results Another way would be to use the Korn shell "grouping" syntax. which we could use to rewrite the above as: ( cmd1 cmd2 : cmdN ) > $results The grouping technique has several advantages.pl. and appends a red "New" label if the tip file i mk_index. builds the AIX Tip Arc http://www. Some of Perl's uses include: • • • • Write shell scripts Extract/combine data from one or more files "Clean" data prior to importing into a database Create CGI programs to dynamically build web pages. The first. 2000 Perl (Practical Extraction Report Language) is a programming language that combines the best features of sed. a convenience of shell scripts.org/AIXtip. mk-index. including less typing. builds the HTML file with hyperlinks. The attached Perl programs illustrate some of these capabilities.com/cgi-bin/lis AIX Tip of the Week: Simplifying I/O Redirection Audience: AIX Users Date: December 8. It builds the index page by extracting descriptive information from each sorts the tips by category.bull. awk. reduced I/O overhead (N file opens vs 1 file op such as using a ">" that erases all the accumulated data in the file.AIX Tip of the Week: Use Perl to Create Web Pages Audience: AIX Administrators and End Users Date: June 6.aiche-norcal. AIX Tip of the Week: Using AIX's "skulker" Command to Purge Unwanted Files . and can be obtained for prior releases from http://www-frec.

The skulke cron job during off-peak periods (uncomment the "skulker" line in root's crontab).ibm. you should not include the password in the URL. You can modify skulker to suit loc see: http://www.com/doc_link/en_US/a_doc_lib/cmds/aixcmds5/skulker. 2000 Sometimes when you telnet into a system.profile" and insert the following line: stty erase '^H' AIX Tip of the Week: Using a Web Browser to FTP Files Audience: AIX Users Date: November 25. 2000 Any web browser can be used to ftp files using the standard URL syntax: ftp://username:password@remote_host_name** For security reasons.Audience: Systems Administrators Date: September 1. 2000 AIX's skulker command is a shell script that can be used to periodically purge obsolete or unneeded files.rs6000.htm AIX Tip of the Week: Using stty to Set Backspace Key Audience: AIX Users Date: October 22.the backspace key produces output similar to: $ lss^[[2~^[[2~^[[2~ To fix. type: $ stty erase "BackspaceKey" The permanent solution is to edit your ". The system will prompt for the missing passw ------**Note: the full URL ftp syntax is .

ftp://username:password@remote_host_name:port/path. $ perl -p -i -e "s/LOTUS/IBM/g" * As with any global change command.ibm. 2001 Here's a Perl trick that can simplify editing multiple files to make the same change.com/doc_link/en_US/a_doc_lib/cmds/aixcmds5/svmon. relative to the user id's home directory type = transfer type: a = ascii.i] Where port = the port number for ftp (if different from standard) path = the directory path.type=[a.com/doc_link/en_US/a_doc_lib/aixbman/prftungd/2365c71. To illustrate. For mor http://www. Only root can run the svmon command. the following comm "LOTUS" to "IBM" in all files in the current directory.d.ibm. d = directory listing.htm http://www. use the svmon command. be sure to back up the files before running the command. Determining the Size of AIX Memory Audience: Systems Administrators Date: February 16.htm Installing and Using AIX "man" Pages . For non root users.rs6000.rs6000. i = binary (default) AIX Tip of the Week: Perl Trick to Edit Multiple Files with One Command Audience: AIX Users Date: January 20. 2001 This week's tip provides two useful commands for determining the size of AIX memory. use the command: lsattr -El sys0 | grep realmem A simpler command for root users is: bootinfo -r To determine what is occupying memory.

cmds6 Top Level Navigation Online Navigation AIX Commands Reference AIX Commands Reference AIX Commands Reference AIX Commands Reference AIX Commands Reference AIX Commands Reference 1 2 3 4 5 6 The following filesets are optional. which does not have one.ti .cmds.AIX Base Tech Ref bos.cmds.en_US. To illustrate.base .html. respectively.techref.cmds.html.cmds1 bos.en_US.html.en_US.html. The most common form is man command which lists the help page for "command".en_US.Audience: Users Date: March 9.html.html. If a terminfo file isn't avai the infocmp command.cmds. bos.cmds5 bos.en_US. On the Linux machine: infocmp -I > linux.AIX Commo Tech Ref Using "infocmp" To Create Terminfo Files Audience: Systems Administrators Date: June 14.navigate bos.html. 2001 The "man" command provides online help for AIX commands.cmds4 bos. The filesets a Documentation CD.cmds3 bos. or if you want to find related inf option: man -k searchstring Man pages are not installed by default in AIX.en_US.en_US. the problem is usually ca definitions.topnav.nav bos.techref.en_US.html. for AIX system calls and C library functions. here's how you can create a LINUX terminal definition for AIX. 2001 When a telnet session does not correctly display full screen applications (like vi and smitty). bos. If you don't know the name of a command. The following filesets must be installed for man to work.cmds.html.cmds.en_US.en_US.html.commo . The solution is to copy the "terminfo" file for the terminal to the remote server.cmds2 bos.

ti rsh aixhost "tic /usr/lib/terminfo/linux. Then issue the commands: restart <offset> put <filename> Where <offset> is the size of the aborted file.3**. and "cd" to the target directory. memory AIX oslevel . 2001 The AIX 4. The restart command did not work per the AIX documentation. The "aixhost" is the host name of the remote AIX system. adapters.ti" telnet aixhost The infocmp flag is an uppercase "i".AIX OS level . The restart option is not 100% portable: I've successfully tested "restart" on AIX systems and between AIX/Linux sys Windows. firmware.CPU's . This can be us unstable connections because if the connection fails. 2002 You can use the prtconf command to list your AIX hardware configuration. disk command is available the current version of AIX 4.3 ftp restart command allows you to resume an aborted file transfer at the point it stopped. and it does not appear to be an option in the Solaris documentation.serial number.ti aixhost:/usr/lib/terminfo/linux. including CPU's. model number. and on AIX 5. you only have to transfer the remaining portion of the file. etc) devices verbose (microcode level. etc) adapter cards disks . Here's the procedure I tested. For those running older versions of AIX. in bytes. memory.3. Listing the AIX System Configuration Audience: All Date: January 30. General prtconf lscfg [-v] lscfg -v lsdev -Cc adapter lsdev -Cc disk lsdev -Cc processor lsattr -El sys0 list system configuration devices (-v = verbose for microcode levels. This procedure shoul ftp Checkpoint Restart Audience: AIX Users Date: August 10. her provide the same information. After an aborted file tra Log onto the remote host.rcp linux.

AIX maintenance level . This command only works for AIX 5 which can run e (AIX 4 only runs a 32-bit kernel. the 64 bit applications run faster. First. 2002 Updated: 5/28/02 There are two common misconceptions about 64-bit applications. Otherwise. It's listed under column the "64 output. 64 bit performance is comparable to a 32 bit application.pid #>.) The administrator chooses which kernel at install time.alphaw 64 Bit Commands Audience: Administrators Date: February 9.instfix -i |grep ML lslpp -l .) The bootinfo -K shows whether the kernel is running 32/64 bit. 64-bit applications improve performance when they can access more than 2 GB memory (a 32 bit limitation). Here are a couple useful "64 bit" commands: The bootinfo -y command tells whether the hardware is 32 or 64 bit enabled. Second. Accessi magnitude faster than disk. Generally all hardware since the H70 is The svmon -P <. (This command also shows whether the application is multithreaded under the "Mthrd" column. Another way to determine which kernel is running is the command: genkex | grep 64.installed SW and levels Disk lsvg lsvg lsvg lslv lslv lspv lspv -o -p vgname -l vgname lvname -l lvname -l hdisk# active volume groups disk drives in VG LV's in VG LV detail LV disk location disks LV's residing on a disk Network lsdev -Cc if netstat -rn -List network interfaces -List network gateways **If you can't upgrade to the current version of AIX. 64 kernel. Another misconception is that you need a 64 bit kernel to run a 64 bit applications. You should see something like . you can still download the prtconf tool from http://www. command lists whether a running application is 32 or 64 bit. Both 32 and 64 bit kernels run 64 requires the 64 bit extensions.

ibm.boulder. the "uname -m" command provides a code that identifies the CPU.3 system.1 pmcycles command lists the processor speed.htm .pmsvcs" If you have an AIX 4. The pmcycles command is part of the "bos. 2002 In AIX 5. For more informat http://publib.pmapi.149bf58 a3ec /usr/lib/drivers/syscalls64.ext Determing the CPU Clock Speed Audience: All Date: December 3.com/doc_link/en_US/a_doc_lib/aixbman/prftungd/2365ax5.

3. uname command. there is no direct command to determine processor speed. The pmcycles options are as follows: -m Run on all processors -d Print decrementer speed An example is as follows: # pmcycles This machine runs at 451 MHz If you are not on operating system version later than 4.Appendix D. Determining CPU Speed With operating system versions later than 4.3. you can determine the processor Model ID 02 10 10 11 14 18 1C 20 2E 30 31 34 35 37 38 41 43 43 46 47 48 Machine Type 7015-930 7013-530 7016-730 7013-540 7013-540 7013-53H 7013-550 7015-930 7015-950 7013-520 7012-320 7013-52H 7012-32H 7012-340 7012-350 7011-220 7008-M20 7008-M2A 7011-250 7011-230 7009-C10 Processor Speed 25 25 25 30 30 33 41. the pmcycles command (part of the perfagent.3.6 25 41 20 20 25 25 33 41 33 33 33 66 45 80 Architecture Power Power Power Power Power Power Power Power Power Power Power Power Power Power Power RSC Power Power PowerPC RSC PowerPC .tools fileset) measures Performance Monitor counters. Running the uname -m command produces output of the following form: xxyyyyyymmss where: xx 00 yyyyyy Unique CPU ID mm Model ID (the numbers to use to determine CPU speed) ss 00 (Submodel) By cross-referencing the mm values from the uname -m output with the table below. The speed is returned in Mhz.3.

Second. #!/usr/bin/ksh # Pacific Time: TZ=-16 (see below for explanation) if [ `TZ=-16 date +%d` = "01" ]. search the web for "aix data recovery". don't depend on these tools to recover data. My suggestions are 1. then # Run these commands . 2003 Determining the last day of a month in a shell script can be complicated because each month has a different number o year. tomorrow or two weeks from now. 2003 Updated: November 9.compunix. 2004 Unfortunately. The syntax is counter in forward. None guar A better strategy is prevention.com (For others. there is no "unerase" command in Unix. Here's a trick with the "date" command that simplifies this calculation.. Work as a regular user id Alias the "rm" command as "rm -i".. I use it to archive rotating monthly logs. The best alternative is to restore from a backup (You are maki As a last resort.) However. To illustrate. Subject: Is There an AIX "unerase" Command? Audience: Administrators Date: April 26.Using the "date" Command to Determine the Last Day of the Month Audience: All Date: October 31. you can try a data recovery tool. here are a few example one day: GMT: TZ=-24 EST: TZ=-19 CST: TZ=-18 PST: TZ=-16 This trick can be used to calculate yesterday. "TZ" is relative to GMT time. 3. Copy files before editing Make regular backups . 2. reports. Never work as root for non administration tasks. fi The timezone setting (TZ) setting tricks the date command into thinking it is 24 hours ahead. and a "+" sign means backward. 4. such as the one at http://www.

Sign up to vote on this title
UsefulNot useful