How to store a number along with the sign


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to store a number along with the sign
# 1  
Old 12-08-2010
How to store a number along with the sign

If I use the below
cut -c37-48, the minus sign does not get appended to the number, as the sign is in the 36th Position.

But, If I use cut -c36-48, the minus sign appears infront of the number, but for positive numbers, it throws an error.

How can this be resolved..
# 2  
Old 12-08-2010
please show sample input line/file for us to get exact idea on it.
R0H0N
# 3  
Old 12-08-2010
Quote:
Originally Posted by Haimanti
it throws an error.
You mean cut throws an error? Unlikely, so perhaps you could also post your script?
# 4  
Old 12-08-2010
Code:
abc=`echo <filename> | cut -c37-48`


Last edited by Franklin52; 12-08-2010 at 05:10 AM.. Reason: Please use code tags
# 5  
Old 12-08-2010
Quote:
Originally Posted by Haimanti
abc=`echo <filename> | cut -c37-48`
You're trying to cut a piece of the <filename> (as opposed to a piece of the file itself)?

Please show a part of the input file (filename), and such as it is, change your command to:

Code:
abc=$(cut -c37-48 filename)

# 6  
Old 12-08-2010
but what is there in filename ??
show sample lines please..
R0H0N
# 7  
Old 12-08-2010
Code:
while read each_rec
do
  fin_div_count=`echo "${each_rec}" | cut -c1-2`
  if [ ${fin_div_count} -eq 01 ]
  then
      abc=`echo "${each_rec}" | cut -c37-48 | bc`


Last edited by Franklin52; 12-08-2010 at 05:11 AM.. Reason: Please use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Programming

store information in hash and display number of keys.

I am trying to store this information (info and number) in hash. number is the key and info is value in a hash.i shown my code below. #!/usr/bin/perl use warnings; use strict; use XML::LibXML::Reader; my $file;open $file, 'formal.xml'); my $reader =... (0 Replies)
Discussion started by: veerubiji
0 Replies

2. Shell Programming and Scripting

Store number in a directory

hi all, this is some code in c...i want to write script for this... for(i=0;i<10;i++) { store i in backup directory; } (1 Reply)
Discussion started by: AbhijitIT
1 Replies

3. UNIX for Dummies Questions & Answers

Using GREP/AWK to extract a number and store it as a variable

Hello, I have a question regarding the awk command. Here is the line I need to grep: 1 F= -.13250138E+03 E0= -.13249556E+03 d E =-.174650E-01 mag= 35.2157 Instead of displaying the number in red I would like to store it as a variable such as X. Is there a way to do this? Thanks for any... (3 Replies)
Discussion started by: modey3
3 Replies

4. Shell Programming and Scripting

number sign(#) in sed scripts

Hi. In a simple sed script i have number signs - #. But i can't find any description on their functionality. One thing that i find is that # in sed scripts can mean comment if it is placed in the beginning of the line. I thought may be this undocumented(for me) behavior refers to regular... (1 Reply)
Discussion started by: kukuruku
1 Replies

5. Shell Programming and Scripting

Ability to store number of rows

Hi, I am creating a korn shell script and i'm trying to find out what the total number of rows are in a specific text file and i need to store that number in a variable withing the script. i know wc -l gives you the number, but it also has some leading spaces and then writes out the file name... (2 Replies)
Discussion started by: scabral
2 Replies

6. Shell Programming and Scripting

Sign on/Sign off logging script

I'd like to make a script that I can execute every time I sign on to my linux box that keeps track of the time and allows to me to add a remark to a file. So basically once I log in, I run the script, and it outputs the date and time to a text file (log.txt). But that isn't my problem. I need... (1 Reply)
Discussion started by: Glider
1 Replies

7. UNIX for Advanced & Expert Users

What is the Maximum number of characters that i can store in a variable?

Hi, Can any one tell me, what is the maximum number of characters that can be stored in a variable? Thanks in Advance, Shan (9 Replies)
Discussion started by: pcshan
9 Replies
Login or Register to Ask a Question