fritsimeel :
I have a .csv file with the following values:
N0012,17/01/20,13:31:42,N52:01:58,E004:19:00
I need to remove the N and E from the fourth and fifth column. So the output is:
N0012,17/01/20,13:31:42,52:01:58,004:19:00
I did try using
awk '{gsub(/\N|\;/,$4)}1' file
but it also removes the fist N from the first column.
So I need some assistance with this. Thanks in advance.
RavinderSingh13 :
Could you please try following.
awk 'BEGIN{FS=OFS=","} {sub(/^N/,"",$4);sub(/^E/,"",$5)} 1' Input_file
In case OP wants to substitute any letter (not only N or E) then try following.
awk 'BEGIN{FS=OFS=","} {sub(/^[[:alpha:]]/,"",$4);sub(/^[[:alpha:]]/,"",$5)} 1' Input_file
OR
awk 'BEGIN{FS=OFS=","} {sub(/^./,"",$4);sub(/^./,"",$5)} 1' Input_file
Explanation: Adding detailed explanation for above code here.
awk ' ##Starting awk program from here.
BEGIN{ ##Starting BEGIN section of this awk program from here.
FS=OFS="," ##Setting field separator and output field separator as comma here.
}
{
sub(/^N/,"",$4) ##Using substitute function of awk to substitute starting N in column 4th here.
sub(/^E/,"",$5) ##Using substitute function of awk to substitute starting N in column 5th here.
}
1 ##Mentioning 1 will print edited/non-edited line here.
' Input_file ##Mentioning Input_file name here.
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=220217&siteId=1