update field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting update field
# 8  
Old 12-07-2010
Try:
Code:
awk -vx="\/$defaultStorage1" '{FS=OFS=" "}$1==x{$3="1"}1' file.dat > /tmp/awk.$$
mv /tmp/awk.$$ file.dat

# 9  
Old 12-08-2010
Question

Thank you bartus11.Smilie

It worked.... Smilie

---------- Post updated 12-08-10 at 06:05 PM ---------- Previous update was 12-07-10 at 06:25 PM ----------

hi

Code:
awk -vx="\/$defaultStorage1" '{FS=OFS=" "}$1==x{$3="1"}1' file.dat > /tmp/awk.$$

how can i pass a variable say percentage to be assigned in $2 ??
i tried

Code:
 
awk -vx="\/$defaultStorage1" '{FS=OFS=" "}$1==x{$2=percentage}1' file.dat > /tmp/awk.$$

but not working

Thanks in advance
# 10  
Old 12-08-2010
The same way:
Code:
awk -vx="\/$defaultStorage1" -vpercentage=$some_value '{FS=OFS=" "}$1==x{$2=percentage}1' file.dat > /tmp/awk.$$

# 11  
Old 12-14-2010
Question

Hi,

is it possible to get the value of the correspoinding PERCENTAGE of the defaultStorage1 fields as below :

percentage=awk -vx="\/$defaultStorage1" '{FS=OFS=" "}$1==x{print $2}1' file.dat

thanks in advance
# 12  
Old 12-14-2010
You mean assign the result of AWK command to shell variable? Use this:
Code:
percentage=$(awk -vx="\/$defaultStorage1" '{FS=OFS=" "}$1==x{print $2}1' file.dat)

# 13  
Old 12-14-2010
Question

Actually, i just need the value of the column PERCENTAGE corresponding to the STORAGE field value = defaultStorage1.

But when i use this, the percentage variable is containing the entire table as value.

For e.g. from the table below

/storage_02 64% 0
/storage_01 17% 1

if i am passing defaultStorage as storage_02 i want to get 64 in a variable as output

thanks
# 14  
Old 12-14-2010
U can simply grep the percentage.

Code:
grep "^\/$defaultStorage1" file.dat | cut -f2

R0H0N
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to update field using matching value in file1 and substring in field in file2

In the awk below I am trying to set/update the value of $14 in file2 in bold, using the matching NM_ in $12 or $9 in file2 with the NM_ in $2 of file1. The lengths of $9 and $12 can be variable but what is consistent is the start pattern will always be NM_ and the end pattern is always ;... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

awk to update value in field of out file using contents of another Ask

In the out.txt below I am trying to use awk to update the contents of $9.. If $9 contains a + or - then $8 of out.txt is used as a key to lookup in $2 of file. When a match ( there will always be one) is found the $3 value of that file is used to update $9 of out.txt separated by a :. So the... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

awk to update field in file2 if not the same as file1

Trying to use awk to: update $2 in file2 with the $2 value in file1, if $1 in file1 matches $13 in file2, which is tab-delimeted. The $2values may already be the same so in that case nothing happens and the next line is processed. There are exactly 4,605 unique $13 values. Thank you :). ... (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

awk to update value in field based on another field

In the tab-delimeted input file below I am trying to use awk to update the value in $2 if TYPE=ins in bold, by adding the value of HRUN= in italics. In the below since in line 1 TYPE=ins the 117282541 value in $2 has 6 added because that is the value of HRUN=. Hopefully the awk is a start but I... (2 Replies)
Discussion started by: cmccabe
2 Replies

5. Shell Programming and Scripting

awk to update field file based on match

If $1 in file1 matches $2 in file2. Then the value in $2 of file2 is updated to $1"."$2 of file2. The awk seems to only match the two files but not update. Thank you :). awk awk 'NR==FNR{A ; next} $1 in A { $2 = a }1' file1 file2 file1 name version NM_000593 5 NM_001257406... (3 Replies)
Discussion started by: cmccabe
3 Replies

6. Shell Programming and Scripting

Update a field using awk and keep the formatting.

Look at this simple example. echo " 2 4 6" | awk '{$2+=3;$3-=1}1' 2 7 5 Is there a simple way to update a field and at the same time keep the formatting? I would like to get it like this 2 7 5 I have tested both sub and gsub, it reformat too. (2 Replies)
Discussion started by: Jotne
2 Replies

7. Shell Programming and Scripting

Update field value on a csv file

Hi I have a job status csv file. I want to update the status of the job in the file. Below is the csv file 1,jobname1,in_progress,starttime,somthing,somthing 2,jobname2,completed,starttime,somthing,somthing 3,jobname3,failed,starttime,somthing,somthing... (8 Replies)
Discussion started by: midhun19
8 Replies

8. Shell Programming and Scripting

How to update field value in place?

Dear all: I have a file: 1:00 2:abc 3:12asweand I ran the following awk script on this file: #!/usr/bin/awk -f { i= 1; while(i<=NF) { $i=substr($i, 1, index($i, ":")-1); i++ } }I am expecting the file would become (after running... (7 Replies)
Discussion started by: littlewenwen
7 Replies

9. Shell Programming and Scripting

Update specific field in a line of text file

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

10. Shell Programming and Scripting

Update a field in a file based on condition

Hi i am new to scripting. i have a file file.dat with content as : CONTENT_STORAGE PERCENTAGE FLAG: /storage_01 64% 0 /storage_02 17% 1 I need to update the value of FLAG for a particular CONTENT_STORAGE value I have written the following code #!/bin/sh threshold=20... (1 Reply)
Discussion started by: kichu
1 Replies
Login or Register to Ask a Question