- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: need to check the character length of each lin...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 03:02 AM
01-15-2009 03:02 AM
need to check the character length of each line
Requirement is:
1) each line should have a character count of 1825
2) If not then it should display the line no which is not having the count-1825
I have written a following script for that:
-------------------------------------------
count=1;
while read line
do
if [ ${#line} != 1825 ]
then
echo "Line No:$count length is not 1825" >> TEMPFILE
exit 99;
fi
count=`expr $count + 1`
done < testing
In the above case, 'testing' is the i/p file name and it has got around '876875' lines and so when I tried to execute the script, it is taking minimum of 10 minutes. Could you please let me know how the performance can be improved?
Thanks,
Sathish
- Tags:
- length
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 03:09 AM
01-15-2009 03:09 AM
Re: need to check the character length of each line
You can do it in a more efficient way with basic program in C
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 03:39 AM
01-15-2009 03:39 AM
Re: need to check the character length of each line
grep -nvE '^.{1825}$' filename | cut -d : -f 1
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 05:02 AM
01-15-2009 05:02 AM
Re: need to check the character length of each line
Since you don't specify anything other than the generic "character":
# awk 'length!=1825' file
This excludes newline characters.
The following includes newline characters too:
# perl -ne 'print if length!=1826' file
Regards!
...JRF...
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 09:42 AM
01-15-2009 09:42 AM
Re: need to check the character length of each line
JRF:> awk 'length!=1825' file
JRF, to fulfill sathis's second requirement, shouldn't the awk be something similar to
awk 'length!=1825{print $NR, $0}' file
or
awk 'length!=1825{print $NR}' file
?
HP-Server-Literate since 1979
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 10:04 AM
01-15-2009 10:04 AM
Re: need to check the character length of each line
I missed the addition of the line-number on which the length isn't met (as Michael pointed out):
For 'awk':
# awk 'length!=1825{print NR,$0}' file
...notice that the record-number is 'NR" not '$NR'.
For Perl:
# perl -ne 'print "$. $_" if length!=1826' file
...which again we note _includes_ counting the newline character at the end of each line.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2009 02:03 AM
01-19-2009 02:03 AM
Re: need to check the character length of each line
so something like this might work:
if [ $(wc --chars ${#line}) -ne 1825 ]; then
echo "Line No:$count length is not 1825" >> TEMPFILE
fi
Best regards
Fredrik Eriksson