Hi All,

I am new to scripting. I need your help to removing spaces from a string and assign them to different variables.

Iwant to call script with one command line argument which is file name which containes different attributes their type and different values eg

fdxE1ConfigAdminStatus int 1 2
fdxE1LineType int 1 2 3

Now I want script take one line every time from this file then in that line it will go till end and puts value in different attributes eg

attr1 = fdxE1ConfigAdminStatus
attr2 = int
attr3 = 1 and 2 [possibly an array]

then it goes to second line and do the same and so on

I wrote follwing program

if [ "$1" = "" ]; then
 echo "$0 <attr filename >";
while read line; do
  echo $line;
  echo ${#line};

First traversal of loop containes fdxE1ConfigAdminStatus int 1 2
Now I want to remove spaces after fdxE1ConfigAdminStatus, int, 1 and 2 and put them in different attributes.

This is bash script.

Could you all please help to me to find out a solution.

Thanks in advance

Recommended Answers

All 3 Replies

I'm a little bit confused, but for command line arguments, Linux will automatically split them whenever it sees a space. As for splitting a string, you need to write a parser. I'm not going to do your homework for you, but start researching. (Try "Linux shell script parser")

echo "fdxE1ConfigAdminStatus int 1 2" |
while read name type values ; do
     set -A valarray $(echo $values)
    echo $name $type ${valarray[0]} ${valarray[1]}
    echo "There are $((${#valarray
[*]} - 2)) more values for $name"

Hello friend,

how to remove a string in the file.?

do u have any creative idea.?


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.