![]() |
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 |
| How to Read config (.cfg) files using shell scripting | smallwonder | UNIX for Advanced & Expert Users | 5 | 03-02-2007 12:37 AM |
| Urgent Need for Assistance: Triggering Windows bat files from UNIX | punyenye | Windows & DOS: Issues & Discussions | 0 | 03-16-2006 05:00 AM |
| Config Files | toddjameslane | HP-UX | 0 | 05-19-2005 09:53 AM |
| Apache Config Files | Webwitch | UNIX for Dummies Questions & Answers | 1 | 08-01-2001 03:35 PM |
| new LAN, where are the config files? | softarch | UNIX for Dummies Questions & Answers | 3 | 03-27-2001 02:36 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Assistance with regex and config files
I am trying to write a shell script that will such in data from a config file. The script should mount device nodes that are contained in a config file in the following format:
Code:
# filesystem type # read/write #device # Mount Point xfs w /dev/sda1 /mnt ext3 r /dev/hdc /mnt1 Code:
mount -t xfs w /dev/sda1 /mnt So, assuming that I have a config file as formatted above named mounts.cfg and the following shell script: Code:
FILE="./mounts.cfg"
while read line
do
if [ -z "echo $line | sed '/^ *#/d;s/#.*//'" ]
then
next;
else
mount -t echo "$line | sed '/^ *#/d;s/#.*//'`";
fi
done < $FILE
Thanks Phil Last edited by pryker; 03-04-2008 at 10:13 AM.. Reason: updated posting |
|
||||
|
With awk you can achieve that as follow:
Code:
awk 'NR > 1{print "mount -t " $1 " " $2 " " $3 " " $4}' "./mounts.cfg" | sh
Code:
awk 'NR > 1{print "mount -t " $1 " " $2 " " $3 " " $4}' "./mounts.cfg"
Last edited by Franklin52; 03-04-2008 at 04:05 PM.. Reason: edit code |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|