Changing values only in 3rd column and 4th column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing values only in 3rd column and 4th column
# 1  
Old 09-16-2014
Changing values only in 3rd column and 4th column

Code:
#cat file

testing test! nipw asdkjasjdk ok! what !ok

host server1
check_ssh_disk!102.56.1.101!30!50!/
other

host server 2
des
check_ssh_disk!192.6.1.10!40!30!/

#grep check file|  awk -F! '{print $3,$4}'|awk '{gsub($1,"",$1)}1'
 50
 30
#



Output:


host server1
check_ssh_disk!102.56.1.101!20%!10%!
other

host server 2
des
check_ssh_disk!192.6.1.10!20%!10%!/

# 2  
Old 09-16-2014
Is this what you are trying to achieve?
Code:
awk -F'!' 'NF==5{$3="20%";$4="10%"}1' OFS='!' file

This User Gave Thanks to Yoda For This Post:
# 3  
Old 09-16-2014
Yes, how cn it automatically edit??

---------- Post updated at 09:38 AM ---------- Previous update was at 09:38 AM ----------

its a long large file..with other details in
# 4  
Old 09-16-2014
Redirect the output to a temp file and then move it back to original file:-
Code:
awk -F'!' 'NF==5{$3="20%";$4="10%"}1' OFS='!' file > tmp
mv tmp file

Note: Make a copy of the original file before doing this.
# 5  
Old 09-16-2014

it works, but i need some of the data

cat file|grep check|awk -F'!' 'NF==5{$3="20%";$4="10%"}1' OFS='!'
check_ssh_disk!102.56.1.101!20%!10%!/
check_ssh_disk!192.6.1.10!20%!10%!/


LIKE THIS:
host server1
check_ssh_disk!102.56.1.101!20%!10%!
other

host server 2
des
check_ssh_disk!192.6.1.10!20%!10%!/


# 6  
Old 09-16-2014
No need to use cat & grep, if you want to edit lines starting with check, try:-
Code:
awk -F'!' '/^check/{$3="20%";$4="10%"}1' OFS='!' file

This User Gave Thanks to Yoda For This Post:
# 7  
Old 09-16-2014
thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Solution for replacement of 4th column with 3rd column in a file using awk/sed preserving delimters

input "A","B","C,D","E","F" "S","T","U,V","W","X" "AA","BB","CC,DD","EEEE","FFF" required output: "A","B","C,D","C,D","F" "S", T","U,V","U,V","X" "AA","BB","CC,DD","CC,DD","FFF" tried using awk but double quotes not preserving for every field. any help to solve this is much... (5 Replies)
Discussion started by: khblts
5 Replies

2. Linux

Print the 1st column and the value in 2nd or 3rd column if that is different from the values in 1st

I have file that looks like this, DIP-17571N|refseq:NP_651151 DIP-17460N|refseq:NP_511165|uniprotkb:P45890 DIP-17571N|refseq:NP_651151 DIP-19241N|refseq:NP_524261 DIP-19241N|refseq:NP_524261 DIP-17151N|refseq:NP_524316|uniprotkb:O16797 DIP-19588N|refseq:NP_731165 ... (2 Replies)
Discussion started by: Syeda Sumayya
2 Replies

3. Shell Programming and Scripting

Changing values in the first column.

I have a file which looks like this: 1 3 5 5 3 2 1 5 3 6 3 2 0 5 6 3 2 9 0 4 5 6 4 9 In the first column, instead of 1, I want to place +1 and instead of 0, I want -1 to be put. So the generated file should look like this: +1 3 5 5 3 2 +1 5 3 6 3 2 -1 5 6 3 2 9 -1 4 5 6 4 9 Just to... (9 Replies)
Discussion started by: shoaibjameel123
9 Replies

4. UNIX for Dummies Questions & Answers

Search word in 3rd column and move it to next column (4th)

Hi, I have a file with +/- 13000 lines and 4 column. I need to search the 3rd column for a word that begins with "SAP-" and move/skip it to the next column (4th). Because the 3rd column need to stay empty. Thanks in advance.:) 89653 36891 OTR-60 SAP-2 89653 36892 OTR-10 SAP-2... (2 Replies)
Discussion started by: AK47
2 Replies

5. Shell Programming and Scripting

Print every 5 4th column values as separate row with different first column

Hi, I have the following file, chr1 100 200 20 chr1 201 300 22 chr1 220 345 23 chr1 230 456 33.5 chr1 243 567 90 chr1 345 600 20 chr1 430 619 21.78 chr1 870 910 112.3 chr1 914 920 12 chr1 930 999 13 My output would be peak1 20 22 23 33.5 90 peak2 20 21.78 112.3 12 13 Here the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. UNIX for Dummies Questions & Answers

Changing the values of a column using awk and gsub

Hi, I am using the following code to change NA to X in only the 5th column of my text file: awk '{gsub("NA","x",$5)}1' in.file > out.file How can I modify this code if I want to change NA to X in multiple columns of the text file (i.e. columns 5,6 and 7). Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

7. UNIX for Dummies Questions & Answers

Changing values of a column based on formula

Hi, I have a tab delimited text file with two columns where the second column takes on values between 1 and 6 (including). If the value of the second column, includes 1,2,3 I want to replace it with LOW. If it is 4,5,6 I want to replace it with HIGH. How do I go about doing that? Thanks ... (3 Replies)
Discussion started by: evelibertine
3 Replies

8. Shell Programming and Scripting

1st column,2nd column on first line 3rd,4th on second line ect...

I need to take one column of data and put it into the following format: 1st line,2nd line 3rd line,4th line 5th line,6th line ... Thanks! (6 Replies)
Discussion started by: batcho
6 Replies

9. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

10. Shell Programming and Scripting

How to extract 3rd line 4th column of a file

Hi, Shell script: I would need help on How to extract 3rd line 4th column of a file with single liner Thanks in advance. (4 Replies)
Discussion started by: krishnamurthig
4 Replies
Login or Register to Ask a Question