Hi all,

As the name suggests, sriptingnoob by name scriptingnoob by nature!

I really need some advice, as I am loosing what little hair I have left.

I have a file which contains lines similar to these

MACHINE[1]=192.168.10.1
HOSTNAME[1]=MACHINE1
LOCATION[1]=UPSTAIRS

MACHINE[2]=192.168.20.2
HOSTNAME[2]=SAGE
LOCATION[2]=UPSTAIRS

PRINTER[3]=192.168.10.56
etc

I want to write a script in linux that can be used to add new machines into the file using the next available number. I am happy with writing info into a file etc but I am struggling to work out how to find the next available number for the MACHINES. I want to try and keep with shell scripting rather than having to learn perl etc

Does anyone have any suggestions? I would be most grateful

Well, considering you will need to learning something in either case it might be worth your while to learn something directly suited to this type of behavior. For instance Ruby, Python, or Perl are all easier to use as a newcomer when parsing text; AWK and shell not so much (the AWK part is debatable).

Also, before providing any sample code, what do you mean by next available number? Is there a resource that gives these out? Should it be inferred from the file contents? Are you talking about the indexes or IP addresses? It would help if you clarified a bit.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.