unix

awk passing in a parameter using solaris / sunos

 

take this file , new_list.csv and you wish to see only column 2 with values 14

Tokyo1,3
Tokyo1,3
Tokyo1,3
Tokyo1,3
Tokyo1,3
Tokyo1,3
Tokyo1,3
LONDON1,14

LONDON2,14
LONDON3,14
LONDON4,14
LONDON5,14
LONDON6,14
PARIS1,14
PARIS2,14
PARIS3,14

 

count=14

Using Solaris

awk -vcount=$count -F"," ' ( $2 == '"$count"' )  { print $1 }' new_list.csv
 

 

outputs these values

LONDON1,14
LONDON2,14
LONDON3,14
LONDON4,14
LONDON5,14
LONDON6,14
PARIS1,14
PARIS2,14
PARIS3,14

 

Using Linux , use without quotes around the variable count. like below;

list all files that have been modified today

find ./foundry_*SCRIPTED09* -type f -mtime -1 -print

 

Unix move files older than 7 days

find . -type f -name "*.caf" -mtime +7 -exec mv {} backup/ \;

Advantages of Linux

  • Low cost: Free Licenses as it comes with GNU General Public License.
    Large repositories from which you can freely download high quality software for almost any task you can think of.
  • Stability: Linux doesn’t need to be rebooted often to maintain performance levels. It hardly ever freezes up or slows down over time due to memory leaks and such. Very common to have up-times of hundreds of days (up to a year or more).
  • nawk unix tool

    Awk Utility Awk scans a file (or input) line by line, from the last line, searching for lines that match a specified pattern and performing selected actions ( enclosed in curly braces) on those lines.
    %nawk 'pattern' filename
    %nawk '{action}' filename
    %nawk 'pattern {action}' filename

    -- if the regular expression z is matched anywhere on the line, awk prints the entire line.
    nawk -F: '/z/' file.txt

    -- if the line begins with one or more upper or lowercase letter a's, the entire line is printed.
    nawk '/^[Aa]+/' file.txt

    Syndicate content