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
Performing fast searching operations with a bash script jitendriya.dash Shell Programming and Scripting 3 06-01-2009 01:49 PM
Help!! manipulating file sirrtuan UNIX for Dummies Questions & Answers 2 07-16-2008 05:18 PM
Manipulating File rivendell500 SUN Solaris 2 03-25-2008 10:52 PM
Unix file operations(shell script) nivas Shell Programming and Scripting 6 02-07-2008 07:11 AM
problem in arithmetic operations ithirak17 Shell Programming and Scripting 3 02-06-2007 06:46 AM

Reply
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 07-03-2009
shrijith1 shrijith1 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 3
Need help is manipulating a file with some arithmetic operations using bash script

Friends,
I have a file with contents like:

interface Serial0/4/0/0/1/1/1/1:0
encapsulation mfr
multilink
group 101

Now I need to manipulate the file in such a way that to all the numbers less than 163, 63 gets added and to all numbers greater than 163, 63 gets deducted.(The numbers means the numericals after "group") How do I do this using a bash/shell script?

Thanks
Shrijit
  #2 (permalink)  
Old 07-03-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
hope this will work.. (I couldn't test it)
Code:
awk '{if($0 ~ /^group/){if($2>163){printf "group %d\n",$2-63}else{printf "group %d\n",$2+63}}else{print}}' filename
  #3 (permalink)  
Old 07-03-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
nawk '$1=="group" {$NF+=($NF<163)?63:-63}1' myFile
Reply

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 AM.


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