awk a integer and replace it minus X


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers awk a integer and replace it minus X
# 1  
Old 12-15-2011
awk a integer and replace it minus X

hey, i have a list of devices that looks like so:

Code:
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(358271365120608989UL))),Option<ulong>())))),2098560),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(650586938465599244UL))),Option<ulong>())))),2098560),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(22574479957500438UL))),Option<ulong>())))),4195200),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(93913043472124733UL))),Option<ulong>())))),4195200),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(217131279596132951UL))),Option<ulong>())))),4195200),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(303655871981484697UL))),Option<ulong>())))),4195200),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(392171455982529305UL))),Option<ulong>())))),8390400),

i m trying to awk the size and reduce 5 MB from each line like so:

Code:
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(358271365120608989UL))),Option<ulong>())))),2098555),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(650586938465599244UL))),Option<ulong>())))),2098555),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(22574479957500438UL))),Option<ulong>())))),4195195),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(93913043472124733UL))),Option<ulong>())))),4195195),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(217131279596132951UL))),Option<ulong>())))),4195195),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(303655871981484697UL))),Option<ulong>())))),4195195),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(392171455982529305UL))),Option<ulong>())))),8390195),

i tried a few ways but none of them worked perhaps awk is not the way to go
please advise
thank u.
# 2  
Old 12-15-2011
Code:
$ nawk 'BEGIN{FS="," ; OFS=","} {$(NF-1)=$(NF-1)-5")"; print}' infile

This User Gave Thanks to jayan_jay For This Post:
# 3  
Old 12-15-2011
my problem that some lines dosent have a "," at the end of the line and
then it dosent work like here :
Code:
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(358271365120608989UL))),Option<ulong>())))),2098560),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(650586938465599244UL))),Option<ulong>())))),2098560)
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(22574479957500438UL))),Option<ulong>())))),4195200),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(93913043472124733UL))),Option<ulong>())))),4195200),
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(217131279596132951UL))),Option<ulong>())))),4195200)
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(303655871981484697UL))),Option<ulong>())))),4195200)
VolumeTask(DeviceName(DeviceName(DeviceNameInfo(MultiPathType_UID(Option<GUDeviceID>(GUDeviceID(ulonglong(392171455982529305UL))),Option<ulong>())))),8390400),

is there a quick fix?
thank u
# 4  
Old 12-16-2011
Go with this ..
Code:
$ nawk 'BEGIN{FS=",";OFS=","}!/,$/{$NF=$NF-5")";print}/,$/{$(NF-1)=$(NF-1)-5")"; print}' infile

This User Gave Thanks to jayan_jay For This Post:
# 5  
Old 12-18-2011
thank u ,
but i get the following:

Code:
/tmp/Boaz> nawk 'BEGIN{FS=",";OFS=","}!/,$/{$NF=$NF-5")";print}/,$/{$(NF-1)=$(NF-1)-5")"; print}' test
/,: Event not found.

# 6  
Old 12-18-2011
I always disable bash history expansion with "set -H", or you can escape the "!" with "\".
Code:
perl -pe's/(?<=\)\)\)\),)(\d+)/($1-5)/e' infile

Add "-i" to the perl options if you want in place editing.
This User Gave Thanks to binlib For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace integer string in a variable based on month?

Hi Folks - Linux Version = Linux 2.6.39-400.128.17.el5uek x86_64 I have a process that determines the start and end load periods for an Oracle data load process. The variables used are as follows follows: They are populated like such: However, the load requires the month to be the... (11 Replies)
Discussion started by: SIMMS7400
11 Replies

2. Shell Programming and Scripting

Need help on awk to compare only integer on particular column

Hi, 0.23 2.94% 0.00 0.00% 17.8G 55.7% 19.6G 40.9% 630 0.00% 0.06 0.77% - - 7524M 22.9% 15.6G 32.6% - - From the above sample output. I need to compare whether the 6th field is more than 10G..if so print the entire line. Here the 6th field is memory TIA (5 Replies)
Discussion started by: Sumanthsv
5 Replies

3. Shell Programming and Scripting

awk to add plus or minus to fields and split another field

In the tab-delimited input below I am trying to use awk to -10 from $2 and +10 to $3. Something like awk -F'\t' -v OFS='\t' -v s=10 '{split($4,a,":"); print $1,$2-s,$3+s,a,$5,$6} | awk {split(a,b,"-"); print $1,$2-s,$3+s,b-s,b+s,$5,$6}' input should do that. I also need to -10 from $4... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

sed help, Find a pattern, replace it with same text minus leading 0

HI Folks, I'm looking for a solution for this issue. I want to find the Pattern 0/ and replace it with /. I'm just removing the leading zero. I can find the Pattern but it always puts literal value as a replacement. What am I missing?? sed -e s/0\//\//g File1 > File2 edit by... (3 Replies)
Discussion started by: SirHenry1
3 Replies

5. Shell Programming and Scripting

Calculating an integer with awk

I would like to extract a number from $0 and calculate if it can be devided by 25. Though the number can also be less then 25 or bigger than 100. How do i extract the number and how can the integer be calculated? String: "all_results">39</span>I am looking for the number between "all_results"> ... (5 Replies)
Discussion started by: sdf
5 Replies

6. Programming

I don't know how to replace input char with appropriate integer

Hi guys, I asked for help on programming forums and no one didn't helped me so I ask for help here. I am playing with some tasks from my book and I can't figure where did I get wrong. From the first program I get a blank screen, program won't generate 10*10 matrix. And second problem is I... (6 Replies)
Discussion started by: solaris_user
6 Replies

7. Shell Programming and Scripting

awk returns an integer?

I need to extract a value from a text file into a ksh script, and change the last two letters to "00". awk gets the right value (2500 in this example), but the variable has no value. I use the following command: StartTime=expr nawk 'NR==20 {print $11;exit}' $New_FILE echo 1 $StartTime... (4 Replies)
Discussion started by: Iliklev
4 Replies

8. UNIX for Dummies Questions & Answers

Add comma to integer using AWK

Srr for being pain her let say i have a data in a file like this 1@1000 2@2000 4@4000 5@7770 6@8998 7@80008 i am a newbie in Unix i need to add a comma to integer using AWK function. for example, 1,000 or 80,008 how can i do that ps. i'm using bash shell (1 Reply)
Discussion started by: Nutter
1 Replies

9. Shell Programming and Scripting

Replace floating-point by integer in awk

Hi, I am trying to write a script to extract multiple sets of data from a chemistry output file. The problem section is in the following format... Geometry "geometry" -> "geometry" 1 Pd 46.0000 -0.19290971 0.00535260 0.02297606 2 P ... (7 Replies)
Discussion started by: smadonald1
7 Replies

10. UNIX for Dummies Questions & Answers

awk or grep for integer only

how do you print the lines that contain integers only, using grep or awk? thanks , apalex ------------------ this file below: qwerty 01234 asdfgh 01234 qwer12 asdf05 will be: 01234 01234 qwer12 asdf05 (5 Replies)
Discussion started by: apalex
5 Replies
Login or Register to Ask a Question