- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Unix Scripting
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
Forums
Discussions
Discussions
Discussions
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
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
03-30-2004 05:50 PM
03-30-2004 05:50 PM
Unix Scripting
I have a scripting question.
I have a unix file named source which contains the following text
Password:
cpi_quarter cpi face_currency
-------------------------- -------------------- -------------
Dec 1 2002 12:00AM 139.500000 aud
Mar 1 2003 12:00AM 141.300000 aud
Jun 1 2003 12:00AM 141.300000 aud
Sep 1 2003 12:00AM 142.100000 aud
(return status = 0)
I would like to reformatted to a CSV file as per the attachment.
Any ideas would be appreciated.
Thanks
Oktya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2004 05:55 PM
03-30-2004 05:55 PM
Re: Unix Scripting
cat source | grep -v Password | grep -v cpi_ | grep -v status | sed s/\ /\,/g
--------------------------,--------------------,-------------
Dec,1,2002,12:00AM,139.500000,aud
Mar,1,2003,12:00AM,141.300000,aud
Jun,1,2003,12:00AM,141.300000,aud
Sep,1,2003,12:00AM,142.100000,aud,
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2004 05:57 PM
03-30-2004 05:57 PM
Re: Unix Scripting
Thanks for the prompt response, I have attached the file to another message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2004 06:22 PM
03-30-2004 06:22 PM
Re: Unix Scripting
#!/bin/bash
grep -v -e '^Password:' -e '^(return status' -e '^ *$' source | awk '{
if (NR==1) { printf "%s,%s,%s\n", $1, $2, $3}
else
printf "%s %s %s %s,%s,%s\n", $1, $2, $3, $4, $5, $6
fi
}'
In words:
- grep removes lines with patterns mentioned (including empty lines)
- awk prints the first record (NR==1) using format different from the other records.
JP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2004 08:31 PM
03-31-2004 08:31 PM
Re: Unix Scripting
cat YOURFILE|awk '
/^\(return status/ {next}
/^Password/ {next}
/^$/ {next}
{ for (i=1;i<=NF;i++)
printf ("%s,", $i)
printf ("\n")
}
'
-- Graham