- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- AWK - FS and output
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-09-2006 04:28 AM
03-09-2006 04:28 AM
it has 7 fields.
Any thoughts on how I can redefine output?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 04:35 AM
03-09-2006 04:35 AM
Re: AWK - FS and output
try
awk -FS: '{gsub("\t",",");print $0}' filename
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 04:40 AM
03-09-2006 04:40 AM
Re: AWK - FS and output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 04:41 AM
03-09-2006 04:41 AM
Re: AWK - FS and output
# tr "\t" ","
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 04:47 AM
03-09-2006 04:47 AM
Re: AWK - FS and output
If I do:
awk '{print $1"'"$2","....}' infile > outfile
the fields separate on white space with commas, But if it try to tag the "tab" with FS or F the original file is retained in the output file.
I think it is something specific with the field splitting.
I've tried "" ' ' no quotes, around the "\t"
any other ideals?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 04:48 AM
03-09-2006 04:48 AM
Solution- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 04:50 AM
03-09-2006 04:50 AM
Re: AWK - FS and output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 04:51 AM
03-09-2006 04:51 AM
Re: AWK - FS and output
Why not simply use tr to replace tab's by comma's?
Do you need to worry about commas in the tab seperated fields, within quoted strings perhaps?
Similarly, can there be tabs in (quoted) fields in the input file?
Simple sample solution:
/mnt/root # cat > x
a b c d e
/mnt/root # od -b x
0000000 141 040 142 011 143 040 144 011 145 012
0000012
Using FS (I is silent :-) and OFS:
/mnt/root # awk 'BEGIN{FS="\011"; OFS=","}{print $1,$2,$3,$4,$5,$6,$7}' x
a b,c d,e,,,,
Using simple gobal substitute:
/mnt/root # awk '{gsub(/\011/,",",$0); print}' x
a b,c d,e
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 04:53 AM
03-09-2006 04:53 AM
Re: AWK - FS and output
Here's an awk construct that would help...
# awk -F"\t" '{OFS=",";print c$1c,c$2c,c$3c,c$4c,c$5c,c$6c,c$7c}' c='"' inp >out
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 04:53 AM
03-09-2006 04:53 AM
Re: AWK - FS and output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 04:56 AM
03-09-2006 04:56 AM
Re: AWK - FS and output
Could you post a sample of your tab delimited file since that would help in deciphering all the special or invisble characters that need to be accounted for or escaped.
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 05:54 AM
03-09-2006 05:54 AM
Re: AWK - FS and output
Sandman,
that is about the best I can do, it contains private info.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 05:58 AM
03-09-2006 05:58 AM
Re: AWK - FS and output
In the First Name field there are a bunch with FN MI, so I would have to substr off the middle initial as well. I don't think the person that build the SQL output realized that.. I am going to take it back to her and have her work it from the Informix side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 06:03 AM
03-09-2006 06:03 AM
Re: AWK - FS and output
This may accomodate your requirements:
# perl -pe 's/(.+?)\t+/"$1",/g;s/,([^"]+?)$/,"$1"/' filename
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 06:09 AM
03-09-2006 06:09 AM
Re: AWK - FS and output
I am going take a step back before I chase the damn goose around the barnyard.
This file she gave acts as if the entire row is one field unless I break it down from the Whitespace.. (which maybe what I wind up doing.. I appreciate the help..
I am going to get the informix syntax book out and work with the person on formatting the output file from Informix instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 06:14 AM
03-09-2006 06:14 AM
Re: AWK - FS and output
this is the output from your first AWK statement
awk -F"\t" '{OFS=",";print c$1c,c$2c,c$3c,c$4c,c$5c,c$6c,c$7c}' c='"' Conn*csv > rex.con
"","","","","","",""
"referencecode firstname lastname group homephone emailaddress institution ","","","
","","",""
"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 06:23 AM
03-09-2006 06:23 AM
Re: AWK - FS and output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 06:23 AM
03-09-2006 06:23 AM
Re: AWK - FS and output
Okay, these all all string fields so to produce a CSV file w/o headings then create an awk file, my.awk, like this:
function do_csv_string(x)
{
gsub("\"","\"\"",x)
return "\"" x "\""
}
{
printf("%s,%s,%s,%s,%s,%s,%s\n",
do_csv_string($1),do_csv_string($2),
do_csv_string($3),do_csv_string($4),
do_csv_string($5),do_csv_string($6),
do_csv_string($7))
}
Invoke as awk -F '
This will correctly enclose each string in double quotes are required by CSV format and , in addition, will escape each quote within a string with an additional quote.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 06:26 AM
03-09-2006 06:26 AM
Re: AWK - FS and output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 06:30 AM
03-09-2006 06:30 AM
Re: AWK - FS and output
awk -F "\t" -f my.awk < infile > outfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 06:33 AM
03-09-2006 06:33 AM
Re: AWK - FS and output
the output file is not correct..
I am going to bug the SQL programmer a bit when she gets out of her meeting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 06:33 AM
03-09-2006 06:33 AM
Re: AWK - FS and output
the output file is not correct..
I am going to bug the SQL programmer a bit when she gets out of her meeting.
Thanks for the assistance.. I think the source file might be the real problem here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2006 06:39 AM
03-09-2006 06:39 AM
Re: AWK - FS and output
One step closer..
Thanks guys..