![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Insert a line including Variable & Carriage Return / sed command as Variable | lowmaster | Shell Programming and Scripting | 2 | 05-20-2009 12:26 AM |
| Sed variable substitution when variable constructed of a directory path | alrinno | Shell Programming and Scripting | 2 | 07-11-2008 03:24 PM |
| Enviornment Variable in B shell (I call it nested variable) | princelinux | Shell Programming and Scripting | 4 | 07-02-2008 02:35 AM |
| Replace variable with a user defined variable | ce124 | Shell Programming and Scripting | 1 | 04-15-2007 03:56 PM |
| ksh: A part of variable A's name is inside of variable B, how to update A? | pa3be | Shell Programming and Scripting | 4 | 03-30-2005 12:29 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Using AWK as variable?
hello guys,
hope u can help im trying to integrate awk in a variable and then display the values in the variable which i would then use as a menu. my code goes like this .... OPTIONS= awk '{print $1}' /etc/fstab select opt in $OPTIONS; do if [ "$opt" = "$opt" ]; then #the code is $opt = $opt because $OPTIONS contains alot of other values. while opt already has a selected value# echo "executing..." done .... .... |
|
||||
|
You're not far away with your OPTIONS= bit.
Are you sure you want $1 from fstab, and not $2 (the FS mount point)? In any case fstab may contain comments and blank lines, so you should remove these. Code:
set -A OPTIONS $(grep -Ev "^#|^$" /etc/fstab | awk '{print $1}')
Code:
echo ${OPTIONS[0]}
echo ${OPTIONS[1]}
etc.
Code:
OPTIONS=$(grep -Ev "^#|^$" /etc/fstab | awk '{print $1}')
|
|
||||
|
An update to this problem :
im thinking of using awk '$2 ~ /^\/home/ {sub(/$/,",usrquota",$4); print; next} {print}' infile to search for specific column and replace it with other values. However, i want to use the $opt (assume that i use mountpoint in this variable) , thus it would look something like this awk '$2 ~ /^/$opt/ {sub(/$/,",usrquota",$4); print; next} {print}' infile and thus want this line to edit column based on what the user selects. However, im getting errors. |
|
||||
|
By "specific columns" I read you to mean "specific values in specific columns"?
The code Code:
awk '$2 ~ /^/$opt/ {sub(/$/,",usrquota",$4); print; next} {print}' infile
Code:
awk '$2 ~ opt {sub(/$/,",usrquota",$4); print; next} {print}' opt="^$opt" infile
|
![]() |
| Bookmarks |
| Tags |
| awk, variables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|