Assistance with regex and config files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assistance with regex and config files
# 1  
Old 03-04-2008
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

I then want to place the data into a variable so I can do something in the script like so:

Code:
mount -t xfs w /dev/sda1 /mnt

I need to have comments in the config file so need to ignore them when sucking in the configuration.

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

but it gives me errors as apparently even though I am using sed to get rid of commented lines the variable still has some value associated with it. There has to be a better way to do this? any suggestions would be appreciated.

Thanks

Phil

Last edited by pryker; 03-04-2008 at 10:13 AM.. Reason: updated posting
# 2  
Old 03-04-2008
With awk you can achieve that as follow:

Code:
awk 'NR > 1{print "mount  -t " $1 " " $2 " " $3 " " $4}' "./mounts.cfg" | sh

Try this first to see if you get the desired command.

Code:
awk 'NR > 1{print "mount -t " $1 " " $2 " " $3 " " $4}' "./mounts.cfg"

Regards

Last edited by Franklin52; 03-04-2008 at 04:05 PM.. Reason: edit code
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk assistance - Comparing 2 csv files

Hello all, I have searched high and low for a solution to this, many have come really close but not quite what I'm after. I have 2 files. One contains GUID's, for example: 8121E002-96FE-4C9C-BC5A-6AFF20DACECD 84468F30-F3B7-418B-81F0-0908E80792BF A second file, contains a path to the... (8 Replies)
Discussion started by: tirmUK
8 Replies

2. Windows & DOS: Issues & Discussions

(VS 2008) New build config looking files from other folder build config

Hi Team, My new build configuration always looking for the files from the build where i copied from. please help me to resolve this. I am using Visual studio 2008.It has Qt 4.8. plugins,qml,C++ development I created new debug_new build configuration with additional preprocessor from the... (1 Reply)
Discussion started by: SA_Palani
1 Replies

3. Shell Programming and Scripting

Assistance with an awk code to split files but keep the header

---------- Post updated at 11:48 AM ---------- Previous update was at 11:46 AM ---------- Hello all I have an awk code that successfully creates separate text files based on the first six letters of the second field. What it doesn't do is preserve the header into each resulting file. ... (6 Replies)
Discussion started by: colecandoo
6 Replies

4. Shell Programming and Scripting

Assistance for sorting files

Hi there, I have tried using the "find" command to do this but to no avail as the "find -mtime" command I used descend to the directories from my current working directory. Say in "directoryA" has multiple files and those files are created on a daily basis. Under "directoryB", there are... (4 Replies)
Discussion started by: chewku
4 Replies

5. Shell Programming and Scripting

Dhcp.config file scripting assistance

Hello everyone! I am brand new at this forum thing and wanted to thank all of you for your time and help in advance for helping me troubleshoot my issue. I am fairly new to shell scripting and scoured the entire internet to find a solution for my issue to no avail and hope you're able to help. ... (2 Replies)
Discussion started by: sedrocks
2 Replies

6. Shell Programming and Scripting

Need Assistance with gzipping files with same names

Hello, I have an issue on a webserver where I have a perl script rotating and moving the logs to an archive directory where they are gzipped. This is working fine. The problem is when there is tracing enabled on my webserver where the tracelogs are rotated whenenver they reach 100Meg and they... (2 Replies)
Discussion started by: techwiz45
2 Replies

7. UNIX for Dummies Questions & Answers

Assistance with combining, sorting and saving multi files into one new file

Good morning. I have a piece of code that is currently taking multiple files and using the CAT.exe command to combine into one file that is then sorted in reverse order based on the 3rd field of the file, then displayed on screen. I am trying to change this so that the files are being combined into... (4 Replies)
Discussion started by: jaacmmason
4 Replies

8. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

9. Shell Programming and Scripting

parsing config file to create new config files

Hi, I want to use a config file as the base file and parse over the values of country and city parameters in the config file and generate separate config files as explained below. I will be using the config file as mentioned below: (config.txt) country:a,b city:1,2 type:b1... (1 Reply)
Discussion started by: clazzic
1 Replies

10. Windows & DOS: Issues & Discussions

Urgent Need for Assistance: Triggering Windows bat files from UNIX

Hello, Is there a way to trigger a Windows bat file or program on a different machine from a different UNIX server using KSC file? I hope you can assist me with this. Thanks! (0 Replies)
Discussion started by: punyenye
0 Replies
Login or Register to Ask a Question