#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%!/
Is this what you are trying to achieve?
awk -F'!' 'NF==5{$3="20%";$4="10%"}1' OFS='!' file
1 Like
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
Redirect the output to a temp file and then move it back to original file:-
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.
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%!/
No need to use cat
& grep
, if you want to edit lines starting with check
, try:-
awk -F'!' '/^check/{$3="20%";$4="10%"}1' OFS='!' file
1 Like
thank you