Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to count the row amount of a file and get header and footer with empty  row in unix script

Posted on 2011-09-07
5
Medium Priority
?
2,558 Views
Last Modified: 2012-05-12
There is 1 file FILE.txt , use unix script to get the header and footer rows, count the row amount except header and footer

fdfasdaAggpotrt
1204 500 5 435 46509 65 90650
5409tq09 wtr9w0yt90w009re9tr
vbfdfdbgb002istgj ojoi
(empty row)
(empty row)

i) There maybe is empty row after the footer
ii)check the header 8 position must be "A"
iii)check the footer 10-13 value must equal the row count amount of the file except the header and footer

issue;
head -n 1 FILE.txt  , can get the header
but tail -n 1 FILE.txt can NOT get the correct footer

any advice ?

thanks
0
Comment
Question by:SayYou_SayMe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36500561
footer:
grep -v '^$' FILE.txt | tail -1

Count row (included header and footer)
grep -v '^$' FILE.txt  | wc  -l
   The number subtract  2 will be the number you want.
expr  `grep -v '^$' FILE.txt  | wc  -l`  -  2
0
 

Author Comment

by:SayYou_SayMe
ID: 36506618
thanks Wesly_chen

grep -v '^$' FILE.txt | tail -1

can not get the last row, it still get the emty row
0
 
LVL 38

Accepted Solution

by:
wesly_chen earned 2000 total points
ID: 36506650
grep -v '^[ ]*$' FILE.txt | tail -1    
   There is space in [ ]
0
 

Author Comment

by:SayYou_SayMe
ID: 36507201
thanks wesly_chen

it seems working

i) how to get the header 8 position charector
ii)how to get the footer 10-13
0
 
LVL 38

Assisted Solution

by:wesly_chen
wesly_chen earned 2000 total points
ID: 36507386
head -n 1 FILE.txt  |  awk '/???????A/ {print "Good header"}'

grep -v '^[ ]*$' FILE.txt | tail -1  | perl -ne 'print "$1\n" if /.{9}(\d{3})/;'
or
grep -v '^[ ]*$' FILE.txt | tail -1  | perl -ne 'print "footer\n" if /.{9}(\d{3})/;'
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question