The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 10:28 AM
How print number bisla.yogender Shell Programming and Scripting 4 04-28-2008 06:51 AM
print or display certain number of file jerardfjay Shell Programming and Scripting 2 04-05-2008 11:12 AM
grouping of objects and print their number cdfd123 Shell Programming and Scripting 3 10-04-2007 01:49 AM
How to print number of lines with awk ? maheshsri Shell Programming and Scripting 1 11-18-2005 02:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-06-2007
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
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
  #2 (permalink)  
Old 09-06-2007
Nidhi2177 Nidhi2177 is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 9
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
  #3 (permalink)  
Old 09-06-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
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
  #4 (permalink)  
Old 09-06-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
or you can do something like this

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

Thanks
Namish
  #5 (permalink)  
Old 09-06-2007
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
Hey please try this one,

awk ' { printf ("%d\n", $0-1) } ' <<File Name>>
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0