Advertisement

07.31.2008 at 02:04PM PDT, ID: 23612474 | Points: 50
[x]
Attachment Details

AWK PARSING

Asked by vihar123 in Linux Programming, Unix Systems Programming, Perl Programming Language

Tags:

Hi
I have a pipe delimited file, I want to check if the length of the fourth field is >2. In that case fourth field is replaced with empty Otherwise the line is printed as it is.

eg: As below

If length(F4)>2 then the output should be
F1 | F2 | F3 || F5 ......
else
F1 | F2 | F3 | F4 | F5  ......

I am using the code as below. But it is giving a syntax error. What shall I change with in

awk -F'|' 'BEGIN {OFS="|"} {if (length($4)>2) $4="" else $4=$4; print $0}' data_fileStart Free Trial
1:
awk -F'|' 'BEGIN {OFS="|"} {if (length($4)>2) $4="" else $4=$4; print $0}' data_file
[+][-]07.31.2008 at 02:13PM PDT, ID: 22133580

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628