![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Strip time from date in a file | ChicagoBlues | UNIX for Dummies Questions & Answers | 4 | 03-24-2009 05:06 PM |
| how to strip rows from a text file? | ihot | Shell Programming and Scripting | 5 | 10-16-2007 10:21 PM |
| How to strip the contants from a file | isingh786 | UNIX for Dummies Questions & Answers | 2 | 12-16-2005 07:11 PM |
| how to strip out the contents of file using grep | isingh786 | UNIX for Dummies Questions & Answers | 11 | 11-28-2005 07:09 PM |
| How to strip apostrophe from a file | aquimby | Shell Programming and Scripting | 8 | 06-23-2005 04:04 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi, I've been trying (and failing miserably) all morning to strip from a CSV file the time from it. Can somebody point me in the right direction on how to do this using sed or awk? The file looks like: Code:
"James","07/20/2009-14:40:11" "Steve","08/06/2006-02:34:37" "John","11/03/2008-12:12:34" and i want to strip it to make it look like: Code:
"James","07/20/2009" "Steve","08/06/2006" "John","11/03/2008" using cut -d '-' -f 1 < file is not an option since some names may contain dashes.... Thanks a lot in advance for your help. |
|
||||
|
Possibilities, with sed: Code:
sed 's/\(.*\)-.*/\1"/' file with awk: Code:
awk -F, '{sub("-.*","\"",$NF)}1' OFS="," file
Regards |
| Bits Awarded / Charged to Franklin52 for this Post | |||
| Date | User | Comment | Amount |
| 08-05-2009 | figaro | N/A | 1,000 |
|
||||
|
Quote:
With sed you can save substrings with \(.*\) and recall them back with \1, \2, \3 etc. with: Code:
/\(.*\)-.*/ we saved a substring \(.*\) before the last dash, and with: Code:
\1"/ we print a double quote " after the substring \1. Hope this helps. |
![]() |
| Bookmarks |
| Tags |
| awk, csv, sed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|