Sponsored Content
Top Forums Shell Programming and Scripting string manipulation with tabs Post 302288790 by chebarbudo on Wednesday 18th of February 2009 03:09:12 AM
Old 02-18-2009
Thanks vgersh99 for your help.
Unfortunately, this doesn't work with bash and I'm not allowed to install other shells.
But I came up with this new solution:
Code:
patricio@videos:~$ cat myscript
for record in $(mysql ndtv -e 'SELECT CONCAT(id, "-", ip) FROM terminal ORDER BY ip' | sed '1d'); do
    ip=${record##*-}
    id=${record%%-*}
    echo -en "================================================================================\15"
    echo -n "Terminal $id ($ip) "
    if ping -c1 -w1 $ip > /dev/null 2>&1; then
        echo
        ssh root@$ip "$1";
    else
        echo 'UNREACHABLE '
    fi
done
patricio@videos:~$ ./myscript 'hostname'
Terminal 3 (172.16.100.162) ====================================================
terminal3
Terminal 4 (172.16.121.151) ====================================================
terminal4
Terminal 5 (172.16.121.152) ====================================================
terminal5
Terminal 19 (172.16.121.153) ===================================================
terminal18
Terminal 17 (172.16.121.154) UNREACHABLE =======================================
Terminal 6 (172.16.146.151) ====================================================
terminal6
Terminal 7 (172.16.146.152) ====================================================
terminal7
Terminal 14 (172.16.150.151) UNREACHABLE =======================================
patricio@videos:~$

Fot some reason that I don't understand, if I keep using while, only the first line is parsed:
Code:
patricio@videos:~$ cat myscript
mysql -u ndtv -pndtv ndtv -e 'SELECT CONCAT(id, "-", ip) FROM terminal ORDER BY ip' | sed '1d' | while IFS= read -r record; do
    ip=${record##*-}
    id=${record%%-*}
    echo -en "================================================================================\15"
    echo -n "Terminal $id ($ip) "
    if ping -c1 -w1 $ip > /dev/null 2>&1; then
        echo
        ssh root@$ip "$1";
    else
        echo 'UNREACHABLE '
    fi
done
patricio@videos:~$ ./myscript 'hostname'
Terminal 3 (172.16.100.162) ====================================================
terminal3
patricio@videos:~$

Can you identify the problem?
Santiago
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

string manipulation

Hi, I have searched this long and hard and don't seem to see another post on this issue. I have two strings each with the same characters but in a different order. String1=”word” String2=”dwor” I want to test them to show their similarity. Unfortunately I can't do a sort so that they will... (9 Replies)
Discussion started by: Cactus Jack
9 Replies

2. UNIX for Dummies Questions & Answers

string manipulation

Hi, I have a file with rows of text like so : E100005568374098100000015667 D100005568374032000000112682 H100005228374060800000002430 I need to grab just the last digits(bolded) of each line without the proceeding text/numbers. Thanks (5 Replies)
Discussion started by: james6
5 Replies

3. Shell Programming and Scripting

String manipulation

Hi, i am just gettin exposed to UNIX. Could anyone of u help me out with dis problem..? i have a variable 'act' which has the value as follows, echo $act gives -0- -0- -----0---- 2008-06-04 -0- -0- echo "$act" | awk '{print ($act)}' gives, -0- -0- -----0---- 2008-06-04 -0- -0- I... (2 Replies)
Discussion started by: jerrynimrod
2 Replies

4. UNIX for Dummies Questions & Answers

String manipulation

I am doing some training for a job I have just got and there is an exercise I am stuck with. I am not posting to ask a question about logic, just a trivial help with string manipulation. I would appreciate if somebody could at least give me a hint on how to do it. Basically, the intelligent part... (8 Replies)
Discussion started by: Dantastik
8 Replies

5. Shell Programming and Scripting

string manipulation

i have a file that contains a pattern like this: ajay 1234 newyork available kumar 2345 denver singh 2345 newyork ajay 3456 denver kumar 3456 newyork singh 3456 delhi available ajay 4567 miami kumar 4567 miami singh 4567 delhi i want to search for each line... (5 Replies)
Discussion started by: ajay41aj
5 Replies

6. Homework & Coursework Questions

String Manipulation

Write a shell program to display the position of the right - most character in a given input string. Example : Input : RAHUL Output : L is in the 5th position also tell me how to count length of string and how to find the position of specific character in left most side. Homework... (0 Replies)
Discussion started by: shashwat2691
0 Replies

7. Shell Programming and Scripting

Deleting part of a string : string manipulation

i have something like this... echo "teCertificateId" | awk -F'Id' '{ print $1 }' | awk -F'te' '{ print $2 }' Certifica the awk should remove 'te' only if it is present at the start of the string.. anywhere else it should ignore it. expected output is Certificate (7 Replies)
Discussion started by: vivek d r
7 Replies

8. Shell Programming and Scripting

String Manipulation

I'm making a little game in Perl, and I am trying to remove the first instance of a character in an arbitrary string. For example, if the string is "cupcakes"and the user enters another string that contains letters from "cupcake" e.g: "sake"the original string will now look like this (below)... (3 Replies)
Discussion started by: whyte_rhyno
3 Replies

9. Shell Programming and Scripting

String manipulation.

If a have a variable with a first and last name. and say the variable looks like this... FIRST LAST how could process the variable to look like First .L bash 3.2 (osx) (3 Replies)
Discussion started by: briandanielz
3 Replies

10. UNIX for Beginners Questions & Answers

How to check string contain multiple tabs or spaces?

str contains tabs and multiple spaces str="hello world. How are you?" I want to check string start with hello world, and my code is: if ]world"* ]]; then echo "found" else echo "not found" fi Not work Other solution may work is to replace all tabs and... (4 Replies)
Discussion started by: cmdcmd
4 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 06:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy