![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Read a file line by line | VENC22 | UNIX for Dummies Questions & Answers | 4 | 10-30-2008 11:09 AM |
| read the file line by line | kittusri9 | Shell Programming and Scripting | 3 | 04-24-2008 09:26 AM |
| How to read element of line of file | ahjiefreak | High Level Programming | 1 | 04-20-2008 03:21 PM |
| read line from file | rein | Shell Programming and Scripting | 5 | 04-15-2005 03:32 AM |
| How to read from a file line by line and do stuff | spaceship | Shell Programming and Scripting | 4 | 03-17-2005 09:47 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
How to read last line of a txt file?
I need to read the last file for a particular day, such as, "Jun 13" because the CSV file is cumulative for the entire day, so I don't want all the previous files, I just want the last file, for that day.
I ran an 'ls -al | grep "June 13" > myLs.txt' (simplified) to list all files from that day. So.. instead of using a bunch of greps and cuts and then expr comparisons to find the last file for that day based on date/time. I'm just assuming that the last line of each myLs.txt will be the last file for that day. Does awk have a "last line" variable? I was looking for it and I only found ones for number of "fields per record" and "current record number", but no "number of records total". Hmm... I guess it would be better if i just, wc -l the textfile and then redirect that into a variable which I will then use in my awk command to echo the last line..... That would work wouldn't it.. hmm.. Last edited by yongho; 06-13-2005 at 01:45 PM.. |
|
||||
|
hrmm
firstVar=`wc -l < ls.txt` # get wc -l
firstVar=`echo $firstVar| tr -d ' '` # remove extra spaces echo "firstVar:${firstVar}" # echo test to see if var worked secondVar=`awk "END {print $$firstVar}" ls.txt` # awk to print last line of file Hm... I think I'm complicating things. I'm getting closer. ah hah! There's a tail command. Last edited by yongho; 06-13-2005 at 02:20 PM.. |
|
|||||
|
Quote:
sed '$!d' # method 1 sed -n '$p' # method 2 # print first line of file (emulates "head -1") sed q sed1liners |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|