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
05-13-2002 09:16 PM
05-13-2002 09:16 PM
I trying to extract the fields in a txt file separated by commas as below:
abc,hhh,lll,kkk,ppp,
dajd,dkjdk,nnn
mmm
I tried using the script below to extract the these fields, place them into an array and write the array contents into a file.
cat test.sh:
BEGIN {
split($0, fieldArray, ",")
for(i in field){
print field[i]
field[i] >> groupfile
}
}
However, it does not produce any results into the groupfile, but produces a parse error at:
field[i] >> groupfile
I tried running the script as follows on the command line:
$awk -f test.sh inputfile
How should I solve this problem ?
Also, what if I were to have 2 different separators in the input file:
wmt:*abc-nn-mm:306:abc,kkk,ppp,...
....,abn
I would only need to extract the fields separated by the commas, not the colons.
How should also do this?
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2002 09:43 PM
05-13-2002 09:43 PM
Solutiontry this:
awk '{
split($0, field, ",");
for (i in field) {
print field[i] >> groupfile
}
}' input_file
In split you can use a regular expression as seperator. if you want to use * and , as separator, just try:
split ($0, field, "[*,]")
Heiner
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2002 09:44 PM
05-13-2002 09:44 PM
Re: AWK

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2002 10:13 PM
05-13-2002 10:13 PM
Re: AWK
It produced an ^Invalid char '`' in expression.
Is the sign after awk, a ` or ' and the sign after closing statement a ' or `, as either one produces the same error...?
Please advice.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2002 10:41 PM
05-13-2002 10:41 PM
Re: AWK
try this
cat filename | akw -F"," '{ print $1 $2 $3 }'
cheers
JOhn.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2002 10:51 PM
05-13-2002 10:51 PM
Re: AWK
If the text file has only very little entries, then it works. Unfortunately, the file is rather huge with lots of such entries separated by commas.
Please advice.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2002 11:00 PM
05-13-2002 11:00 PM
Re: AWK
These are single-quotes (the ones above the ? key).
The following works fine for me:
awk '{
split($0, field, ",");
for (i in field) {
print field[i]
}
}' input_file >> ./groupfile

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2002 12:36 AM
05-14-2002 12:36 AM
Re: AWK
can you attach a section of the file so we know what we are dealing with
cheers
John.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2002 12:43 AM
05-14-2002 12:43 AM
Re: AWK
Try:
awk -F, '{for (i=1;i<=NF;i++){print $i}}' infile > outfile
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2002 01:34 AM
05-14-2002 01:34 AM
Re: AWK
aa,bb,dvfgrh:nfbe,fgr;hfhr-z
243,9474632 jfkweh,fdfwe
l1:/tmp 103 > perl -naF, -e '$"="\n";print"@F"' xx
aa
bb
dvfgrh:nfbe
fgr;hfhr-z
243
9474632 jfkweh
fdfwe
l1:/tmp 104 >