08-24-2010
replacing field in specific line in a file
Hi,
I know there are lots of threads on replacing text within files, usually using sed or awk. However, I find it hard to adapt examples that I found to my specific case. I am kind of new to UNIX and have hard times learning the syntax either for sed or awk so I would appreciate any help. Here's what I want to do:
I have a file containing user information
PIN000:FirstName.LastName:AccountNumber:Balance
I use cut to retreive Balance and place it into a variable and do calculations with it, but I don't know how to replace the Balance in the file above with new Balance that I get.
For example,
withdrawsum=number
Balance=&(($Balance - $withdrawsum))
then I want to replace the Balance part of the file so that when I exit the script, the changes remain and the next time I try to read Balance from the user file, I get the changed one.
For example,
user file:
PIN123:John.Smith:10203040:1000
so the Balance=1000
lets say that
withdrawsum=10
So once I've done the subtraction from the balance,
Balance=$(($Balance - $withdrawsum))
I want the new balance to be overwritten in the old balance place, so the file would look like this:
PIN123:John.Smith:10203040:980
Any thoughts? Thanks in advance for your help.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I wrote a script which extracts data from 2 tables (joining the tables together) and outputs the fields to a csv file.
the output may look something like
scenario 1: a,b,c,d,1,2,3,4 or
scenario 2: a,b,c,d,,,,
now, in the second scenario, there are some empty fields at the end of... (3 Replies)
Discussion started by: Darek
3 Replies
2. UNIX for Dummies Questions & Answers
hi,
i currently have a file with columns similar to this
customer name owed
CID123 John 300
CID342 harry 500
at present i use use awk to find the amount owed by the customer using the customer ID (CID).
if the customer spends more money how would i go about using sed/awk etc to... (2 Replies)
Discussion started by: skinnygav
2 Replies
3. Shell Programming and Scripting
Hi Guys,
I have a file like this:
aaa b c d e f
fsss g h i k l
qqq r t h n
I want:
aaa b c d e f
fsss g h i k l
qqq r t h , n
ggg p t e d u
qqq i o s , k (2 Replies)
Discussion started by: npatwardhan
2 Replies
4. Shell Programming and Scripting
Hi,
I'm attempting to rename some files that have spaces in them. Without linking sed commands together is it possible to replace the first three "." to " ".
File.name.is.long.ext -> File name is long.ext
I can get the desired effect with
echo "File.name.is.long.ext" | sed 's/\./ /g;s/... (5 Replies)
Discussion started by: vectox
5 Replies
5. Shell Programming and Scripting
Say the input was as follows:
Brat 20 x 1000 32rf
Pour 15 p 1621 05pr
Dart 10 z 1111 22xx
My program prompts for an input, what I want is to use the input to locate a specific field. Like if I type in, "Pou" then it would return "Pour" and just "Pour"
I currently have this line but it is... (6 Replies)
Discussion started by: Bungkai
6 Replies
6. Shell Programming and Scripting
I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work.
Brief overview:
I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies
7. Shell Programming and Scripting
I have a text file like this:
subject1:LecturerA:10
subject2:LecturerA:40
if I was given string in column 1 and 2 (which are subject 1 and LecturerA) , i need to update 3rd field of that line containing that given string , which is, number 10 need to be updated to 100 ,for example.
The... (6 Replies)
Discussion started by: bmtoan
6 Replies
8. Shell Programming and Scripting
Hi All,
I am very new to shell scripting and tried to search this in the forum but no luck.
Requirment:
I have an input file which is comma separated. I need to replace the value in 4th column with another value. This has to happen for all the lines in the file.
Sample data:
Input... (2 Replies)
Discussion started by: arunkumarsd
2 Replies
9. Shell Programming and Scripting
Greetings.
I've got a csv file with data along these lines:
Spumoni's Pizza Place, Placemats n Things, Just Lamps
Counterfeit Dollars by Vinnie, Just Shades, Dollar StoreI want to replace the entire comma-delimited field if it matches something ending in "Place" or beginning with "Dollar",... (2 Replies)
Discussion started by: palmfrond
2 Replies
10. UNIX for Beginners Questions & Answers
I'm new with scripting and I can't seem to figure out what I should do to get the output that I want.
My file content would be below.
ID2|ID3 |ID4|ID5 |
I'm trying to replace the field of ID3 which has a fixed length of 10 characters, for each entry I have placed on a .txt file... (5 Replies)
Discussion started by: asdfghjkl
5 Replies
LEARN ABOUT DEBIAN
roar_vs_volume_get
roar_vs_volume_get(3) RoarAudio Programmer's Manual roar_vs_volume_get(3)
NAME
roar_vs_volume_get, roar_vs_volume_mono, roar_vs_volume_stereo - Get or set volume for audio stream
SYNOPSIS
#include <roaraudio.h>
int roar_vs_volume_get (roar_vs_t * vss, float * l, float * r, int * error);
int roar_vs_volume_mono (roar_vs_t * vss, float c, int * error);
int roar_vs_volume_stereo (roar_vs_t * vss, float l, float r, int * error);
DESCRIPTION
Those functions are used to get or set volume for the given stream.
roar_vs_volume_get() gets the volume for the given stream in stereo form as a left and a right component (L/R). If you need the mono volume
just devide the sum of both by two. See examples below.
roar_vs_volume_mono() sets the mono volume for the stream. Balance information is not kept.
roar_vs_volume_stereo() sets the stereo volume for the stream as left and rigth component (L/R).
PARAMETERS
vss The VS object for wich volume is get or set.
l, r, c
The volume for left, right or center (mono) channel. Value is a float in range zero to one. Zero means this channel is fully muted.
One means the channel is passed without altering the amplitude.
Small numerical errors are detected and corrected. Bigger errors will result in a out of range error.
Note that to mute the stream you MUST NOT use volume setting but roar_vs_mute(3).
error This is a pointer to a integer used to store the error value in case of error. This can be NULL if not used but it is very recom-
mended to use this error value to report good error messages to the user.
RETURN VALUE
On success these calls return 0. On error, -1 is returned.
EXAMPLES
Getting mono volume:
float l, r, c;
int err;
if ( roar_vs_volume_get(vss, &l, &r, &err) == -1 ) {
/* handle error */
}
c = (l + r)/2.;
SEE ALSO
roarvs(7), libroar(7), RoarAudio(7).
RoarAudio May 2011 roar_vs_volume_get(3)