- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Reformatting Text with AWK.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2008 11:12 AM
тАО01-31-2008 11:12 AM
user is generating a file.
"Whitman, Slim J",slim@HOTMAIL.COM,Public Schools,01/17/2008,60,
Supposed to be "CSV", however, format "" FULLNAME
I need to grab only email, district, date, and score.
Used following command:
awk -F'"' '{print $3, $4, $5, $6, $7}' filename.csv > outputfilename.csv
Since the "Full Name" is encapulated in "" I had to use -F'"' to leave the comma in place, if I use ',' it removes all commas.
Get following:
,slim@HOTMAIL.COM,Public Schools,01/17/2008,60,
Don't need leading comma..
Any thoughts appreciated.
Rex M
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2008 11:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2008 11:38 AM
тАО01-31-2008 11:38 AM
Re: Reformatting Text with AWK.
given the FS is a double qoute, then you really only needed to print $3, as the *first* field is null (line begins w/ separator), the second field is now the full name, and the 3rd field is the rest of the line.
if you are absolutely positive that the name field will always have a comma in it, the following will work:
awk -F, -v OFS=, '{print $3,$4,$5,$6}'
if there is a case where there that can't be relied on, then the following will work as long as the name is surrounded by quotes:
cut -f 3 -d'"' filename.csv | sed -e 's/^,//g' -e 's/,$//g' > outputfilename.csv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2008 11:38 AM
тАО01-31-2008 11:38 AM
Re: Reformatting Text with AWK.
# cat file
"Whitman, Slim J",slim@HOTMAIL.COM,Public Schools,01/17/2008,60,
# awk -F, '{OFS=",";print $3,$4,$5,$6}' file
slim@HOTMAIL.COM,Public Schools,01/17/2008,60
~hope it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2008 11:48 AM
тАО01-31-2008 11:48 AM
Re: Reformatting Text with AWK.
Got it working.
no offense to Sandman and oldschool I used Jim's coding. The others worked as well for any one whose curious.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2008 11:49 AM
тАО01-31-2008 11:49 AM
Re: Reformatting Text with AWK.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2008 11:53 AM
тАО01-31-2008 11:53 AM
Re: Reformatting Text with AWK.
NO POINTS FOR THIS...
Sandman's code is really an improvement over mine. His trims the trailing comma, too. My suggestion merely addressed the fundamental question you asked.
Regards!
...JRF...