"Simple" echo/reading variable question...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "Simple" echo/reading variable question...
# 1  
Old 08-25-2011
"Simple" echo/reading variable question...

Hello, I have a simple(I think) question!
Although simple, I have been unable to resolve it, so I hope someone can help! OK, here it is:

1)I have an awk script that prints something, such as:
Code:
awk '{print $2}' a > x

so x might hold the value of say '10'

2)Now, I just want to check to see if this value is greater than 0
Code:
if [[ ($x -gt 0) ]]

however, the above statement does not work!
Similarily, when I type:
Code:
echo $x

I just get a blank line! How do I get $x to actually read my value of x? Thanks!!

Last edited by Franklin52; 08-25-2011 at 02:56 PM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 08-25-2011
Code:
x=$(awk '{print $2}' a)
echo $x

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 08-25-2011
Much thanks!
Smilie
# 4  
Old 08-25-2011
external utilities like awk/cut/sed are efficient when run on batches of data, but using them to operate on single lines is extremely wasteful. They take time to load and quit; imagine only being able to say one word per phone call.

To read and tokenize input from a file without awk, you can use the read builtin, which will be literally hundreds of times faster.

Code:
read A B C < file

which will attempt to split the line into at least three tokens. The line 'a b c d e f g' would get split into A='a', B='b', C='c d e f g'.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 08-25-2011
Corona, thank you very much! That's very useful Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Basic question on "echo"

what happens when I echo asterisk? Please don't hijack other peoples' thread; post our own new one as required by forum rules! (5 Replies)
Discussion started by: ithenr00
5 Replies

2. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

3. Shell Programming and Scripting

Question about Special Shell Variable "$-"

Question: How I can change the shell option in my current environment, which I want to change the result of the command echo $-. Background: Special variable $-. It means the current shell option, and in my ENV, the result of this command as follows. -bash-3.2$ echo $- himBH -bash-3.2$ ... (2 Replies)
Discussion started by: ambious
2 Replies

4. AIX

echo $varibla | mail -s "subject" "xxx@xxx.com" not ruuning as expected

Hi Folks, As per the subject, the following command is not working as expected. echo $variable | mail -s "subject" "xxx@xxx.com" Could anyone figure it out whats wrong with this. I am using AIX box. Regards, (2 Replies)
Discussion started by: gjarms
2 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

7. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

8. UNIX for Advanced & Expert Users

A question/problem about oracle "tns listener" and "enterprise manager"

hi, I have a problem about the Oracle related components. I'm not able to find any answer yet, and waiting for your responses... Here is the configuration of my system: * an IBM P550 machine, * an AIX 5.3 running on it and * an oracle database, already installed on it. The problem (or... (1 Reply)
Discussion started by: talipk
1 Replies

9. UNIX and Linux Applications

A question/problem about oracle "tns listener" and "enterprise manager"

hi, I have * an IBM P550 machine, * an AIX 5.3 running on it and * an oracle database, already installed on it. The problem (or question of my own) is: Oracle tns listener, "CT_LISTENER", and the enterprise manager (EM) of the instance, which is uniq instance and called... (0 Replies)
Discussion started by: talipk
0 Replies

10. Solaris

question for "echo"

what is the mean: echo -n "^0;!*^G" thanks (3 Replies)
Discussion started by: chris_chang
3 Replies
Login or Register to Ask a Question