Sponsored Content
Top Forums Shell Programming and Scripting Replacing numbers in bash scripts Post 302424542 by bluesmodular on Tuesday 25th of May 2010 02:35:34 PM
Old 05-25-2010
CPU & Memory Replacing numbers in bash scripts

Hi,

I have lines in some files that look exactly as below, and the line numbers they occur in are always the same. (Lines 136-139)

W 0.00000000 0.00000000 2.00000000
W 0.50000000 0.50000000 2.50000000
W 0.00000000 0.00000000 3.00000000
W 0.50000000 0.50000000 3.50000000

I'd like to replace the last number in each row for each file by numbers related to the variable $vacheight, so that the median of these 4 numbers is always half of $vacheight.

The files are all named "run_example", but are in different folders named "examples#" where # is a number from 140 to 199.

As a related example, Line 117 reads:
Code:
  celldm(3)   = 5.000,

Below is the relevant section of code that works for Line 117 and increments the number on Line 117 by 0.1 each time, in a different folder.

Code:
vacheight=`expr 4.500`
for i in */run_example; do
    printf '117s/= [^,]*/= %s/\nwq\n' "$vacheight" | ed -s "$i"
    vacheight=$(echo "scale=3; $vacheight + 0.100" | bc)
done

Thank you very much for your help!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sed - Replacing numbers w/asteriks in random location in a file

I have a file which contains lots of text (comment field). I would like to parse through the comment field which can be up to 255 characters long and look for anything that seems to resemble, say, a credit card number or customer account number, etc. and replace the numbers with asteriks (*). ... (9 Replies)
Discussion started by: giannicello
9 Replies

2. Shell Programming and Scripting

How to parse large numbers of shell scripts

I am trying to parse hundreds of shell scripts to determine how they related to each other. Ideally for every script, I would get an output of: What other scripts it calls What files it reads Environment variables it accesses Any ideas on how to do this? TIA! (2 Replies)
Discussion started by: bliss
2 Replies

3. Shell Programming and Scripting

replacing numbers greater than 0 with 1

I have some ASCII files containing numerous numbers. What I'd like to do is replace all numbers greater than 0 with 1. Examples of the numbers include: - 000011 and 000042 Thanks (4 Replies)
Discussion started by: vrms
4 Replies

4. Shell Programming and Scripting

Need help in finding and replacing port numbers.

Hi All, I am trying to write a shell script which firstly will search some files and then increase the port numbers mentioned in them by a certain no. let me clear it with an example- suppose there r few files a,b,c,d.... file a's content- <serverEntries xmi:id="ServerEntry_1"... (3 Replies)
Discussion started by: ankushsingh10
3 Replies

5. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

6. UNIX for Dummies Questions & Answers

Replacing Tivoli Alerts in Shell scripts..!

Hello All, Currently in our current production environment in the existing shell scripts we were using Tivoli software to send email alerts, now we have a request from the client to replace the Tivoli with Fog Light software to send the email alerts. Could you please tell me whether it is... (0 Replies)
Discussion started by: Ariean
0 Replies

7. Shell Programming and Scripting

Preserving Empty Lines while Replacing Numbers

Greetings, I am using tcsh to write a script that will replace the numbers in a file with a single number, the caveat is that this file has blank lines which are necessary for another step down the line so I need to preserve the blank lines. I have tried sed and awk but both will collapse the... (1 Reply)
Discussion started by: bonesy
1 Replies

8. Shell Programming and Scripting

Mapping and replacing numbers in two files

hi i have two files one of the form 1 2 2 45 3 56 4 98 5 6598 6 98 7 10 8 0 9 15 10 56 This file's significance is that it maps the number in first column to that of the number in second column The other file is of the form 1 2 (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

9. UNIX for Dummies Questions & Answers

Replacing char in filename scripts fails

Hi I'm trying to remove what I "think" is a bad character. How I got the bad character is when I downloaded jpgs onto my PC and then renamed the files using windows explorer. In cygwin, the files look like $ dir -l total 7840 ----------+ 1 None 3647968 Jul 21 08:41 2012-07-21\ (1).JPG... (6 Replies)
Discussion started by: SailingDreams
6 Replies

10. Shell Programming and Scripting

Replacing a character between two numbers

Hi, I need to replace a character between two numbers (specifically a - to a _). The problem is that they can be *any* numbers. So, I need a one liner to turn a file like this: 1-2 3-4 55-66 4323-12312893 into the following 1_2 3_4 55_66 4323_12312893 Any help would be appreciated! (5 Replies)
Discussion started by: mikey11415
5 Replies
shblk(8)						      System Manager's Manual							  shblk(8)

NAME
shblk - Displays disk blocks, as unformatted hexadecimal numbers SYNOPSIS
/sbin/advfs/shblk [-sb start_block] [-bc block_count] special OPTIONS
Specifies the block on which to start. Specifies the number of blocks to display. OPERANDS
Specifies the device special file for the volume on which the block(s) are located. You can specify the volume by either its character or block device special file name. If you are executing the command from the mount point for the volume, you must specify the character device special file, as speci- fying the block device special file produces a device busy error. DESCRIPTION
The shblk command displays the selected blocks as hexadecimal numbers. The blocks are not formatted to any data or metadata representa- tion. You must be the root user to use this command. EXAMPLES
The following example shows a user whose current file system is mounted on /dev/disk/dsk3a attempting to display block 1 of the a partition on that device. Using the block device special file for the command does not work; using the character device special file does work. The display is truncated on the right due to page width limitations: # /sbin/advfs/shblk -sb 1 -bc 1 /dev/disk/dsk3a open: Device busy # /sbin/advfs/shblk -sb 1 -bc 1 /dev/rdisk/dsk3a 1: 47ff041f c0200002 20009800 00000000 a7a10000 d340000a 43c4153e 4... 1: b7fe0018 47ff0411 47ff0412 d34000e8 00000000 47ff041f 2ffe0000 4... 1: 243d0000 20218050 245d0000 204243e0 b7e10000 40211401 40410524 f... 1: 6bfa8001 47ff041f 2ffe0000 47ff041f 243dffff 23deffe0 20217f90 b... 1: a4410000 b53e0008 b55e0010 b57e0018 e440000b 47f00409 47e1040a 4... 1: a62a0000 47e90410 d34004ad e400000c a42a0008 214a0008 4160300b f... 1: 201fffff a75e0000 a53e0008 a55e0010 a57e0018 23de0020 6b9a8001 2... 1: 47eb0400 c3fffff7 47ff041f 47ff041f 23defff0 43f00011 b75e0000 4... 1: 47ff0412 47ff0413 47ff0414 47ff0415 d3400083 4807f680 a75e0000 4... 1: 40003520 23de0010 6b9a8001 47ff041f 23defff0 b75e0000 b53e0008 4... 1: d340049f 47e00412 47e21410 47e90411 47ff0413 47ff0414 47ff0415 d... 1: 4807d689 45207009 e5200002 201fffff c3e00001 43e00000 a75e0000 a... 1: 23de0010 6b9a8001 47ff041f 47ff041f 23deffe0 b75e0000 b53e0008 b... 1: 47f00409 d3400486 203f03ff 47e0040a 400107a2 4441048a e540000c 2... 1: 47e05410 47ff0411 47e90412 47e03413 47ff0414 47ff0415 d3400051 e... 1: 4140352a 21290001 f55ffff5 a75e0000 a53e0008 a55e0010 23de0020 6... # SEE ALSO
advfs(4), fs(4) shblk(8)
All times are GMT -4. The time now is 06:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy