- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk Question
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
09-18-2003 03:28 AM
09-18-2003 03:28 AM
Awk Question
I have make a script where I want print all fields separate from a , .
I don't know hoe mach fields there are.
This is a script
cat try.out |while read line
do
line1=`echo $linea |awk 'BEGIN {OFS=","}
{for(i=1;i<=NF;i++)print $i}'`
echo $line1
done
but when I see the output I don't see , between the fields.
Please help
Filo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 03:49 AM
09-18-2003 03:49 AM
Re: Awk Question
It would be simpler to use "printf" which prints formatted text as in
printf "%s,",$i
which will print $i followed by a comma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2003 03:53 AM
09-18-2003 03:53 AM
Re: Awk Question
Rgds,
JL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2003 05:25 AM
09-19-2003 05:25 AM
Re: Awk Question
dont't know exactly what you need, but look at this:
echo 'a b c\nd\te f' |
awk -v ORS=, '{for(i=1;i
gives the following output:
a,b,c
d,e,f
So try
awk -v ORS=, '{for(i=1;i
There is no need for cat and Shell-variables.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2003 06:15 AM
09-19-2003 06:15 AM
Re: Awk Question
If I undrrstend you correct the fields is separated with spaces and you want output separated with commas. Why not use tr.
Try:
echo "ddd GGG" |tr " " ","
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2003 06:24 AM
09-19-2003 06:24 AM
Re: Awk Question
{for (idx=1;idx
printf("%s\n",$NF);
}
Then run it in your script as:
awk -f try.awk < try.out > outputfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2003 06:54 AM
09-19-2003 06:54 AM
Re: Awk Question
consider multiple spaces and TABs seperating fields, or white space at the beginning or at the end of a line ... . 'tr' won't do it, then.
mfG Peter