Using Awk script to check length of a character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using Awk script to check length of a character
# 1  
Old 07-02-2008
Using Awk script to check length of a character

Hi All ,
I am trying to build a script using awk that checks columns of the înput file and displays message if the column length exceeds 35 char.

i have tried the below code but it does not work properly
Quote:
#!/bin/ksh

file=$1

FIELD="21 22 23 27 28 30 32 34 36 38 40 41"

for i in $FIELD; do

awk -v fd=$FIELD 'BEGIN { FS=";" }
{
if (length($fd) > 35 )
record=NR }
END {
printf ( "Feild of %d line is more than 35 charcters\n ", record );
}' $file
done
# 2  
Old 07-02-2008
Code:
awk 'BEGIN{
s="21 22 23 27 28 30 32 34 36 38 40 41"
split(s,numbers," ")
FS=","
}
{
 for (i in numbers) {
  if (length($(numbers[i])) >=35 ) {
    print $(numbers[i])
  }
 }
}'  $1

# 3  
Old 07-02-2008
Many Thanks ghostdog74 it works fine .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delimit file based on character length using awk

Hi, I need help with one problem, I came across recently. I have one input file which I need to delimit based on character length. $ cat Input.txt 12345sda231453 asd760kjol62569 sdasw4g76gdf57 And, There is one comma separated file which mentions "start of the field" and "length... (6 Replies)
Discussion started by: Prathmesh
6 Replies

2. Shell Programming and Scripting

Get column number with the same character length

so, i want to tail about the last 3000 lines of a log file and find the column that has the same number of characters across all 3000 lines (or most of the 3000 lines) tail -3000 logfile | while read line do ColumnCharCount=$(for eachwordorwhatever in "${echo $line}" do ... (8 Replies)
Discussion started by: SkySmart
8 Replies

3. Shell Programming and Scripting

Record length check fails due to '\' character

When I check the length for the records in the file, it does not give me the correct value. I used wc -l command. Example records: abcdefghij abcd\efghij abcdefghi Expected output is: 10 11 9 But the output returned is 10 10 9 Please help me on this issue. (10 Replies)
Discussion started by: Amrutha24
10 Replies

4. Shell Programming and Scripting

Check for length which exceeds specified length in a line

Hi, I have a issue, I need to loop through a comma delimited file and check for the length which exceeds specified length , if Yes truncate the string. But my problem is , I do not have to check for all the fields and the field lenght is not same for all the fields. For ex: Say my line... (9 Replies)
Discussion started by: rashmisb
9 Replies

5. Shell Programming and Scripting

Awk: Searching for length of words between slash character

Dear UNIX Community, I have a set of file paths like the one below: \\folder name \ folder1 \ folder2 \ folder3 \ folder4 \\folder name \ very long folder name \ even longer name I would like to find the length of the characters (including space) between the \'s. However, I want... (6 Replies)
Discussion started by: vnayak
6 Replies

6. Shell Programming and Scripting

perl or awk, field length check

Hi Everyone, 1.txt a;1234;134;1111111 b;123;123;1111111 c;123;1334;1111111 d;1234;1234;1111111 output a;1234;134;1111111 c;123;1334;1111111 d;1234;1234;1111111 if field2 legth>3 or field3 length >3, then output. Please advice. Thanks (4 Replies)
Discussion started by: jimmy_y
4 Replies

7. Shell Programming and Scripting

Need awk script to compare 2 fields in fixed length file.

Need a script that manipulates a fixed length file that will compare 2 fields in that file and if they are equal write that line to a new file. i.e. If fields 87-93 = fields 119-125, then write the entire line to a new file. Do this for every line in the file. After we get only the fields... (1 Reply)
Discussion started by: Muga801
1 Replies

8. AIX

check for a particular character inside a file and substitute with a given character?

i am a newbie to shell script,so i want a kshell script in which i need to check for a particular character inside a file through conditional looping(like if ,case,while)and if that character exists ,then substitute a given character to that character. consider a file test.txt,inside the file... (1 Reply)
Discussion started by: karthikprasathk
1 Replies

9. Shell Programming and Scripting

bash script to check the first character in string

Hello would appreciate if somebody can post a bash script that checks if the first character of the given string is equal to, say, "a" thnx in advance (2 Replies)
Discussion started by: ole111
2 Replies

10. Shell Programming and Scripting

Special Character Check in Shell script

Hi, I'm currently working on a project that requires parsing xml file. One of the field in the xml is shown below (don't remember exactly): <variable="ITEM">12345678</variable> I coded my script keeping in mind that the value denoted in bold will always be a number. After getting just the... (1 Reply)
Discussion started by: mradul_kaushik
1 Replies
Login or Register to Ask a Question