LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-02-2008, 06:06 PM   #1
DandyDan
LQ Newbie
 
Registered: May 2008
Posts: 2

Rep: Reputation: 0
non-numeric argument from output


Hello:

I'm using the following:
Fedora 6 2.6.18.1
bash

I'm extracting a numeric value from a file into a variable. I fail to then perform expr on the the var due to 'non-numeric argument'

Below I am pasting the output from my screen:
# grep octets my.out|awk '{print $4}'
20850897
# myvar=`grep octets my.out|awk '{print $4}'`
# echo $myvar
20850897
# expr $myvar + 1
expr: non-numeric argument
# myvar=20850897
# echo $myvar
20850897
# expr $myvar + 1
20850898

The my.out file contains output from an expect script. I can only assume this file has some hidden characters that render my variables 'non-numeric'.

I have tried sending the output first into another file to rid it of hidden characters, but still it fails.

You can see below that the file containing the output will allways be 1 char larger than a 'clean' file. I can't explain this.

# grep octets my.out|awk '{print $4}'
20850897
# grep octets my.out|awk '{print $4}' > my.out2
# cat my.out2
20850897
# echo 20850897 > my.out3
# cat my.out3
20850897
# ll my.out*
-rw-r--r-- 1 root root 10 May 2 16:02 my.out2
-rw-r--r-- 1 root root 9 May 2 16:02 my.out3

Thanks for any help,
Dan
 
Old 05-02-2008, 06:51 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,341
Blog Entries: 55

Rep: Reputation: 3538Reputation: 3538Reputation: 3538Reputation: 3538Reputation: 3538Reputation: 3538Reputation: 3538Reputation: 3538Reputation: 3538Reputation: 3538Reputation: 3538
Try this?
Code:
myvar="20850897 \\x0^V^J" # meaning CTRL+V,CTRL+J
myvar=${myvar//[^0-9]/}
echo \"${myvar}\"
 
Old 05-05-2008, 11:17 AM   #3
DandyDan
LQ Newbie
 
Registered: May 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks so much. That solved the problem.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find with -exec argument - not giving proper output..how to find... hinetvenkat Linux - Server 4 01-25-2010 06:19 AM
output of one script to another as argument sefaklc Programming 9 09-03-2007 03:06 AM
Shell Scripting - use the output of a command as an argument for another timgiffney Programming 6 04-17-2006 11:13 AM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 04:35 PM
invalid numeric argument Copenhagen Cowboy Linux - General 4 03-29-2001 02:01 PM


All times are GMT -5. The time now is 08:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration