The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read file until certain line position finalight Shell Programming and Scripting 5 05-21-2008 03:16 AM
How to check a word position in a file ? tibo Shell Programming and Scripting 7 01-04-2008 02:20 AM
check position of end of line for some specific lines senthil_is Shell Programming and Scripting 1 11-09-2007 01:19 AM
Spliting the line based on position. senthil_is Shell Programming and Scripting 1 09-26-2007 01:32 AM
urgent- position to comma seprated file uni_ajay_r UNIX for Advanced & Expert Users 3 04-26-2006 01:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-20-2007
evvander evvander is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 4
check position of end of line(URGENT PLS)

I Have to check in a file that all the lines are ending at same posiotin.

Ex : line 1 is ending at position 88
line 2 should at same position i.e 88

Thanks in advance
  #2 (permalink)  
Old 09-20-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Code:
shouldbe=88
awk -v e=$shouldbe '{ if(length($0) != e){print "bad line ", NR} ' filename
  #3 (permalink)  
Old 09-20-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Use nawk or /usr/xpg4/bin/awk on Solaris:

Code:
awk 'FNR==1{len=length;next}
length!=len{printf "Check file %s,record %d\n",FILENAME,FNR}' filename[s]

P.S. For portability use length($0).
  #4 (permalink)  
Old 11-08-2007
senthil_is senthil_is is offline
Registered User
  
 

Join Date: Sep 2007
Location: singapore
Posts: 35
check position of end of line for some specific lines

Have to check in a file that the lines starting with 620 and 705
are ending at same posiotin.


82012345
62023232323
70523949558
62023255454
9999

In the above lines, i have to check the lines starting with 620 and 705 are having the length 94.

Can anyone help. Immediate response is very much appriciated.
  #5 (permalink)  
Old 11-08-2007
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
Use the command given above but change the awk to only look at the relevant lines by doing the following:
awk -v e=$shouldbe '{ /^(620|705)/ if(length($0) != e){print "bad line ", NR} ' filename

Should work
  #6 (permalink)  
Old 11-08-2007
senthil_is senthil_is is offline
Registered User
  
 

Join Date: Sep 2007
Location: singapore
Posts: 35
check position of end of line for some specific lines

Thankyou very much for your immediate response.

But its giving some syntax error.

this is what i used.

shouldbe=94
srcFile=$1

awk -v e=$shouldbe '{ /^(620|705)/ if(length($0) != e){print "bad line ", NR} }' $srcFile

The error is below
==============
syntax error The source line is 1.
The error context is
{ /^(620|705)/ >>> if <<< (length($0) != e){print "bad line ", NR} }
awk: The statement cannot be correctly parsed.
The source line is 1.


Can you please correct it?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0