The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to print largest and smallest number. amp10388 UNIX for Dummies Questions & Answers 2 05-07-2008 07:28 AM
How print number bisla.yogender Shell Programming and Scripting 4 04-28-2008 03:51 AM
print or display certain number of file jerardfjay Shell Programming and Scripting 2 04-05-2008 08:12 AM
grouping of objects and print their number cdfd123 Shell Programming and Scripting 3 10-03-2007 10:49 PM
How to print number of lines with awk ? maheshsri Shell Programming and Scripting 1 11-17-2005 10:19 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-06-2007
Registered User
 

Join Date: Jul 2007
Posts: 82
Stumble this Post!
to print number one less than actual number

suppose we have a file which contains
34
45
56
77
55
66
54
67

so output shud be like
33
44
55
76
54
65
53
66
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-06-2007
Registered User
 

Join Date: Sep 2007
Posts: 9
Stumble this Post!
file_no's content are
34
45
56
77
55
66
54
67


tempfile=file_no
for number in `cat $tempfile`
do
number=$((number-1))
echo $number
done
Reply With Quote
  #3 (permalink)  
Old 09-06-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,538
Stumble this Post!
Code:
zsh 4.3.4% cat file
34
45
56
77
55
66
54
67
zsh 4.3.4% eval printf "%d\\\n" $(printf "\$((%d-1)) " $(<file))
33
44
55
76
54
65
53
66
or:

Code:
zsh 4.3.4% awk '$1=$1-1' file
33
44
55
76
54
65
53
66
Reply With Quote
  #4 (permalink)  
Old 09-06-2007
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 285
Stumble this Post!
or you can do something like this

for line in `cat $file`
do
line=`expr $line - 1`
echo $line
done

Thanks
Namish
Reply With Quote
  #5 (permalink)  
Old 09-06-2007
manas_ranjan's Avatar
Registered User
 

Join Date: Jul 2007
Location: PUNE
Posts: 157
Stumble this Post!
Hey please try this one,

awk ' { printf ("%d\n", $0-1) } ' <<File Name>>
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0