Insert single quote and commas


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Insert single quote and commas
# 1  
Old 09-14-2013
Insert single quote and commas

Hi All,

I have a set of data as below :

Code:
XS012371378 Raj 23-09-12
SH128238948 Andrew 24-08-12
CH273712399 Walsh 12-10-12
JK7249923893 Nick 10-02-13
JP6383791389 Braslin 30-12-13

I want the first column to be extracted separately. I can get this using awk.
Code:
awk '{print $1}' file_name

But then along with that i need the same column as shown below :

Code:
'XS012371378',
'SH128238948',
'CH273712399',
'JK7249923893',
'JP6383791389'

Can you please help me with this.?

Last edited by Scott; 09-14-2013 at 02:25 PM.. Reason: More code tags
# 2  
Old 09-14-2013
Try:
Code:
awk '{print "\047"$1"\047,"}' file_name

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 09-14-2013
The last line without a comma
Code:
awk '{printf "%s", sep"'\''"$1"'\''"; sep=","RS} END {print ""}' file_name

This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 09-14-2013
Hey Bartus

Code:
awk '{print "\047"$1"\047,"}' file_name

This works perfectly fine for me. Much Appreciated.

Thanks a lot.

@MadeInGermany : Bulls Eye. Perfect.

Thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Insert commas

Original content: ACACCTCAT 129 | ACACCTCAT 0 ACACCTCATX 171 | ACACCTCATX 0 ACACRESRT 0 ACACRESRT 0 ACACRESRTX 0 ... (4 Replies)
Discussion started by: loktamann
4 Replies

2. Shell Programming and Scripting

Insert a single quote in front of a line in vi editor

Hello Gurus, I wanted to put a single quote in every where starting with /oradata, and at the end with .dbf. For example I have one line as below: alter database rename datafile /oradata/test.dbf to /oradata_new/test.dbf I wanted as below alter database rename datafile '/oradata/test.dbf' to... (3 Replies)
Discussion started by: pokhraj_d
3 Replies

3. Shell Programming and Scripting

Insert single quote on every word separated by comma

Hello, I have a text file as:-ABC BCD CDF DEF EFGI need to convert as 'ABC', 'BCD', 'CDF', 'DEF', 'EFG' using a unix command anybody can help me out on this. Regards, Jas Please wrap all code, files, input & output/errors in CODE tags. It makes them easier to read and preserves... (12 Replies)
Discussion started by: jassi10781
12 Replies

4. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies

5. Shell Programming and Scripting

Insert Inverted Commas Around Numeric Values

Hi, I am trying to insert Inverted Commas around all the numeric values within a comma seperated string / variable. 1111,2222,3333,4444 I would like it to be: '1111','2222','3333','4444' Note - This string could have a differing amount of numeric values each time the variable is... (4 Replies)
Discussion started by: RichZR
4 Replies

6. Shell Programming and Scripting

How to insert a single quote to each record

I have a file as: 1 New used 1 used New I need o/p as: '1' 'New' 'used' '1' 'used' 'New' (12 Replies)
Discussion started by: karumudi7
12 Replies

7. Shell Programming and Scripting

Replace single quote with two single quotes in perl

Hi I want to replace single quote with two single quotes in a perl string. If the string is <It's Simpson's book> It should become <It''s Simpson''s book> (3 Replies)
Discussion started by: DushyantG
3 Replies

8. UNIX for Dummies Questions & Answers

Insert Commas at fixed positions

Hi I have a text file which is position delimited, i.e. Code1 Description1 Value1 Code2 Description2 Value2 etc. I want to import this file into MySQL so I want to convert the file into Comma delimited format. To do this I want to insert commas at fixed positions on... (7 Replies)
Discussion started by: arossco
7 Replies

9. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

10. UNIX for Dummies Questions & Answers

How do I insert commas/delimiters in File

Hi, Newbie here. Need to convert a txt file to .csv format. There's no character to replace so not sure if I can use sed :confused: . The comma is to be inserted after every certain number of characters in each line... Help! Thanks. (4 Replies)
Discussion started by: mbelen
4 Replies
Login or Register to Ask a Question