Computing.Net > Forums > Unix > Print certain line from a text file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Print certain line from a text file

Reply to Message Icon

Name: CamTu
Date: June 1, 2005 at 08:11:31 Pacific
OS: UNIX
CPU/Ram: NA
Comment:

Hi all,

I have a text file and I want to clean up the file by only print those lines start with the date. Is there anyway I can do that?


Code:

[?25h[?4l[?1l[?3h[?3h
Wed Jun 1 2005 10:44AM
Page 1
SCAD
Location Log Recall Report
Tue May 31 2005 12:00AM to Tue May 31 2005 11:59PM
____________________________________________________________________________________________________ ______________________________
| |
| Locations: 656 SCAD FY101 Transactions: Valid Transaction Type: All Reader Status: Online |
|___________________________________________________________________________________________________ _______________________________|
| | |T| |Reader| | | |M|O|O| | Trans |
| Date | Time |P| Location | Name | ID Number | Cardholder Name | Action |N|F|K| Reason |Amount |

____________________________________________________________________________________________________ ______________________________
|05/31/05|02:55PM|1|FY101 |FY101A|000756582 |Perez, Luz Marina |SUMMER VALIDATIONS | | |Y| | |
|05/31/05|02:55PM|1|FY101 |FY101A|000756582 |Perez, Luz Marina |SUMMER VALIDATIONS | | |Y| | |
|05/31/05|02:56PM|1|FY101 |FY101A|000756582 |Perez, Luz Marina |SUMMER VALIDATIONS | | |Y| | |
|05/31/05|02:59PM|1|FY101 |FY101A| | |No Sale | | |Y| | |
|05/31/05|02:59PM|1|FY101 |FY101A|000756582 |Perez, Luz Marina |SUMMER VALIDATIONS | | |Y| | |
|05/31/05|03:29PM|1|FY101 |FY101A| | |No Sale | | |Y| | |
|05/31/05|05:21PM|1|FY101 |FY101A|000668279 |MCNEAL,CORVET J. |SUMMER VALIDATIONS | | |Y| | |

____________________________________________________________________________________________________ ______________________________

Blackboard Inc. End


[?3l


Thanks

CT



Sponsored Link
Ads by Google

Response Number 1
Name: CamTu
Date: June 1, 2005 at 08:13:41 Pacific
Reply:

Hi all,

I have a text file and I want to clean up the file by only print those lines start with the date. Is there anyway I can do that?


[code]

[?25h[?4l[?1l[?3h[?3h
Wed Jun 1 2005 10:44AM
Page 1
SCAD
Location Log Recall Report
Tue May 31 2005 12:00AM to Tue May 31 2005 11:59PM
____________________________________________________________________________________________________ ______________________________
| |
| Locations: 656 SCAD FY101 Transactions: Valid Transaction Type: All Reader Status: Online |
|___________________________________________________________________________________________________ _______________________________|
| | |T| |Reader| | | |M|O|O| | Trans |
| Date | Time |P| Location | Name | ID Number | Cardholder Name | Action |N|F|K| Reason |Amount |

____________________________________________________________________________________________________ ______________________________
|05/31/05|02:55PM|1|FY101 |FY101A|000756582 |Perez, Luz Marina |SUMMER VALIDATIONS | | |Y| | |
|05/31/05|02:55PM|1|FY101 |FY101A|000756582 |Perez, Luz Marina |SUMMER VALIDATIONS | | |Y| | |
|05/31/05|02:56PM|1|FY101 |FY101A|000756582 |Perez, Luz Marina |SUMMER VALIDATIONS | | |Y| | |
|05/31/05|02:59PM|1|FY101 |FY101A| | |No Sale | | |Y| | |
|05/31/05|02:59PM|1|FY101 |FY101A|000756582 |Perez, Luz Marina |SUMMER VALIDATIONS | | |Y| | |
|05/31/05|03:29PM|1|FY101 |FY101A| | |No Sale | | |Y| | |
|05/31/05|05:21PM|1|FY101 |FY101A|000668279 |MCNEAL,CORVET J. |SUMMER VALIDATIONS | | |Y| | |

____________________________________________________________________________________________________ ______________________________

Blackboard Inc. End


[?3l

[/code]
Thanks

CT


0

Response Number 2
Name: gurubit
Date: June 1, 2005 at 08:20:10 Pacific
Reply:

Hi,

You can use the syntax as given below:

cat <full_path_of_file> | egrep -i 'Sun|Mon|Tue|Wed|Thu|Fri|Sat'

You can also redirect the output the contents to a new log file using the > as redirection.

cat <full_path_of_file> | egrep -i 'Sun|Mon|Tue|Wed|Thu|Fri|Sat' > <newfile>

Hope it helps,
Rajesh


0

Response Number 3
Name: CamTu
Date: June 1, 2005 at 08:29:05 Pacific
Reply:

Rajesh,

In the text file i pasted above, I only need those lines start with |05/31/2005 to be printed. The data will be update periodically, so the date will change too.
Thanks

CT


0

Response Number 4
Name: Jim Boothe
Date: June 1, 2005 at 08:39:53 Pacific
Reply:

You can grep for lines that begin with a specific pattern such as:

grep '^|[01][0-9]/[0123][0-9]/[01][0-9]|'

That greps for dates through year 19.


0

Response Number 5
Name: David Perry
Date: June 1, 2005 at 12:05:45 Pacific
Reply:

You can use the same regex patterns in sed.

sed -n '/^|[0-1][0-9]\/[0-3][0-9]\/[0-9][0-9]/p' infile > outfile


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Print certain line from a text file

Remove blanks from a text file www.computing.net/answers/unix/remove-blanks-from-a-text-file/6582.html

print lines from file www.computing.net/answers/unix/print-lines-from-file/3867.html

Script to delete lines from a file www.computing.net/answers/unix/script-to-delete-lines-from-a-file/7408.html