![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Read a file line by line | VENC22 | UNIX for Dummies Questions & Answers | 4 | 3 Weeks Ago 08:09 AM |
| read the file line by line | kittusri9 | Shell Programming and Scripting | 3 | 04-24-2008 05:26 AM |
| How to read element of line of file | ahjiefreak | High Level Programming | 1 | 04-20-2008 11:21 AM |
| read line from file | rein | Shell Programming and Scripting | 5 | 04-14-2005 11:32 PM |
| How to read from a file line by line and do stuff | spaceship | Shell Programming and Scripting | 4 | 03-17-2005 06:47 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 09:45 AM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 10:20 AM. |
|
#3
|
||||
|
||||
|
Quote:
sed '$!d' # method 1 sed -n '$p' # method 2 # print first line of file (emulates "head -1") sed q sed1liners |
||||
| Google The UNIX and Linux Forums |