Sponsored Content
Top Forums Shell Programming and Scripting nawk won't accept comma as delimiter Post 302596745 by b.hamilton on Wednesday 8th of February 2012 08:03:47 AM
Old 02-08-2012
nawk won't accept comma as delimiter

I have a text file delimited by commas, with three fields (no " marks).

I want to use awk to create a fourth field which is equal to the line number + field 1 + .txt

I've searched this forum and found the following
Code:
nawk -v OFS=';' '{print $0, FNR}' myFile

Which I've amended to change the ; to a , - and it works simply to append the line number at the end.

But when I amend it to the following, it won't accept that the commas is a delimeter and still thinks it should be a space;
Code:
nawk -v OFS=',' '{print $0, FNR "_" $1 ".txt"}' myFile

Field 2 has spaces, and it thinking that £1 is the whole of field 1 and the comma up to the first space in field 2.

Help! How can I get this awk to recognise that the comma is the delimter?

---------- Post updated at 01:03 PM ---------- Previous update was at 12:58 PM ----------

I've sorted this by amending OFS to FS - not sure what the difference is but it seemed to work

Last edited by Franklin52; 02-08-2012 at 09:28 AM.. Reason: Please use code tags for code and data samples, thank you
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

mandrake 8.0 experts...how come it won't accept changes to security settings??

well after a possible hack last week that was a pain in the as* i have reinstalled and i am setting up my security settings before i connect to the internet this time... problem is that when i try to change the security setting using in the control setting the left panel (where the change is... (2 Replies)
Discussion started by: justchillin
2 Replies

2. UNIX for Advanced & Expert Users

rcp won't accept a destination with spaces...

Hello I'm on Tru64 unix 5.1.a I'm trying to execute rcp command like this rcp testfile "user@host.com:/pub/Sales/Sales Reports" and I'm getting an error message rcp: ambiguous target copy works fine if I just put underscore in the destination directory, like Sales_Reports... ... (3 Replies)
Discussion started by: Trusevich
3 Replies

3. Shell Programming and Scripting

awk,nawk,sed, delimiter |~|

RECORD=NEW|~|VENDORN=LUCENT|~|VENDORM=CBX500_REAR|~|NETWORK=ATM|~|SUBNETWORK=N/A|~|SITE=CIL|~|REGION=KN|~|COUNTRY=PS|~|SWITCH=SWITCH1|~|E THERNET=N/A|~|LOOPBACK=N/A|~|SHELF=N/A|~|SLOT=14|~|SUBSLOT=N/A|~|STSCHAN=N/A|~|PORT=S14|~|DS1SLOT=N/A|~|LINE=N/A|~|LPORTID=N/A|~|CARDDESC=N/A|~|CARDTYPE=BAC2RT0... (7 Replies)
Discussion started by: knijjar
7 Replies

4. Solaris

Solaris 10 install won't accept IP address

Hi I am trying to debug an issue with an automated install I have set-up. So to start I just ran a simple ok; boot cdrom - install but when it came to the IP address field it would only take the following format 123.123.123.12 and would not let me enter the last digit Anybody got any... (9 Replies)
Discussion started by: eeisken
9 Replies

5. Shell Programming and Scripting

comma delimiter and space

I have a csv file and there is a problem which I need to resolve. Column1,Column2,Colum3,Column4 ,x,y,z ,d,c,v t,l,m,n ,h,s,k ,k,,y z,j, ,p Now if you see column1 for row 1 and row 4 though they are null there is a space but in case of row2 and row 5 there is no space. I want row... (3 Replies)
Discussion started by: RubinPat
3 Replies

6. Shell Programming and Scripting

Exporting data into Comma Delimiter.

Hi, Requirement: Exporting data from Oracle to UNIX into "Comma" delimiter. Help Needed: I was able to connect to Oracle and import the data. But please let me know while importing the data I need to make it into Comma delimiter flat file. For Example: Source Data - 100 ABC TLead... (6 Replies)
Discussion started by: arunvasu2
6 Replies

7. Shell Programming and Scripting

Replacing Comma delimiter coming inside the data.

Hello, I am having flat file (Comma Delimiter) and the data in the file is as given below. EMPNO, ENAME, DESIGNATION, SALARY 10979, Arun Kumar, Cosultant, 35000 13555, Bidhu Shekar, Senior Consultant, 45000 15000, Kiran, Kumar, Senior, Consultant, 40000 If... (9 Replies)
Discussion started by: arunvasu2
9 Replies

8. UNIX for Dummies Questions & Answers

Making a Tab delimiter file to Comma

How can i make a tab delimiter file to a comma delimiter??? (13 Replies)
Discussion started by: saggiboy10
13 Replies

9. Shell Programming and Scripting

Change the delimiter from Comma to Pipeline

Hello All, I need to convert a csv file to pipeline delimiter file in UNIX. The data in file itself contains comma with double qouted qualifier apart from the comma separator. Let me know how to do it. Appreciate any help if awk can be used to do it. Mentioned below is the sample record of... (14 Replies)
Discussion started by: Arun Mishra
14 Replies

10. Shell Programming and Scripting

Replace comma delimiter by newline

The input file is as below AR,age,marks,roll,section,evin,25,80,456,A,atch,23,56,789,B,eena,24 ,78H245,C,Ps,ot,ecessary,hat,ame comes first then age and rest AR AZ,kevin,25,80,456,A,Satch,23,56,789,Satch,23,56,789,B,Meena,24,78,H245,C,AZ ................ ................ I am writting... (8 Replies)
Discussion started by: millan
8 Replies
DPKG-AWK(1)						      General Commands Manual						       DPKG-AWK(1)

NAME
dpkg-awk - Utility to read a dpkg style db file SYNOPSIS
dpkg-awk [(-f|--file) filename] [(-d|--debug) ##] [(-s|--sort) list] [(-rs|--rec_sep) ??] '<fieldname>:<regex>' ... -- <out_fieldname> .. DESCRIPTION
dpkg-awk Parses a dpkg status file (or other similarly formatted file) and outputs the resulting records. It can use regex on the field values to limit the returned records, it can also be told which fields to output, and it can sort the matched fields. OPTIONS
-f filename --file filename The file to parse. The default is /var/lib/dpkg/status. -d [#] --debug [#] Each time this is specified, it increased the debug level. -s field(s) --sort field(s) A space or comma separated list of fields to sort on. -n field(s) --numeric field(s) A space or comma separated list of fields that should be interpreted as numeric in value. -rs ?? --rec_sep ?? Output this string at the end of each output paragraph. -h --help Display some help. fieldname The fields from the file, that are matched with the regex given. The fieldnames are case insensitive. out_fieldname The fields from the file, that are output for each record. If the first field listed begins with ^, then the list of fields that follows will NOT be output. BUGS
Be warned that the author has only a shallow understanding of the dpkg packaging system, so there are probably tons of bugs in this pro- gram. This program comes with no warranties. If running this program causes fire and brimstone to rain down upon the earth, you will be on your own. This program accesses the dpkg database directly in places, querying for data that cannot be gotten via dpkg. AUTHOR
Adam Heath <doogie@debian.org> DEBIAN
Debian Utilities DPKG-AWK(1)
All times are GMT -4. The time now is 06:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy