Nth field should have space and rest commas


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Nth field should have space and rest commas
# 1  
Old 05-13-2014
Nth field should have space and rest commas

Hello

I was working on a script where the output of my file is
Code:
1234
4567
8973
43214
78965

I need the value in below format of this file.The nth field should have space instead of ,(comma)

1234,4567,8973,43214 78965

I tried the code but not working completely
Code:
 xargs <temp_PP.7250 | sed -e 's/ /,/g' | sed -e 's/,*$/ /g'


Last edited by Corona688; 05-13-2014 at 03:02 PM..
# 2  
Old 05-13-2014
For exactly your sample file, try
Code:
paste -sd',,, ' file
1234,4567,8973,43214 78965

This User Gave Thanks to RudiC For This Post:
# 3  
Old 05-13-2014
Or try:
Code:
paste -sd',' file | sed 's#\(.*\),#\1 #'

# 4  
Old 05-13-2014
Thanks For your support
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Javascript to check field is empty then execute rest of script

I have found this bit of code that nearly does what I want. Basically 3 input fields, I want to copy t2 to t3 as it's typed but only if t1 contains data AND t3 is empty: <input type="text" id="t1" /> <input type="text" id="t2" /> <input type="text" id="t3" /> <script> var t2 =... (4 Replies)
Discussion started by: barrydocks
4 Replies

2. Shell Programming and Scripting

Remove quotes and commas from field

In the attached file I am trying to remove all the "" and , (quotes and commas) from $2 and $3 and the "" (quotes) from $4. I tried the below as a start: awk -F"|" '{gsub(/\,/,X,$2)} 1' OFS="\t" enhancer.txt > comma.txt Thank you :). (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

Replace a value of Nth field of nth row

Using Awk, how can I achieve the following? I have set of record numbers, for which, I have to replace the nth field with some values, say spaces. Eg: Set of Records : 4,9,10,55,89,etc I have to change the 8th field of all the above set of records to spaces (10 spaces). Its a delimited... (1 Reply)
Discussion started by: deepakwins
1 Replies

4. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

5. UNIX for Dummies Questions & Answers

Print Nth to last field

Hey, I'm sure this is answered somewhere but my Googling has turned up nothing. I have a file with data in the following format: <desription of event> at <time and date>The desription of the event is variable length and hence when the list is displayed it is hard to easily see the date (and... (8 Replies)
Discussion started by: RECrerar
8 Replies

6. UNIX for Dummies Questions & Answers

change field separator only from nth field until NF

Hi ! input: 111|222|333|aaa|bbb|ccc 999|888|777|nnn|kkk 444|666|555|eee|ttt|ooo|ppp With awk, I am trying to change the FS "|" to "; " only from the 4th field until the end (the number of fields vary between records). In order to get: 111|222|333|aaa; bbb; ccc 999|888|777|nnn; kkk... (1 Reply)
Discussion started by: beca123456
1 Replies

7. Shell Programming and Scripting

CSV with commas in field values, remove duplicates, cut columns

Hi Description of input file I have: ------------------------- 1) CSV with double quotes for string fields. 2) Some string fields have Comma as part of field value. 3) Have Duplicate lines 4) Have 200 columns/fields 5) File size is more than 10GB Description of output file I need:... (4 Replies)
Discussion started by: krishnix
4 Replies

8. Shell Programming and Scripting

Replace field with commas with field without commas

Hey guys, I have the following text: 1,2,3,4,5,6,'NULL','when',NULL,1,2,0,'NULL' 1,2,3,4,5,6,'NULL','what','NULL',1,2,0,1 I need the same text with the word NULL without commas u know something like this: 1,2,3,4,5,6,NULL,'when',NULL,1,2,0,NULL 1,2,3,4,5,6,NULL,'what','NULL',1,2,0,1 ... (1 Reply)
Discussion started by: lmyk72
1 Replies

9. Shell Programming and Scripting

Need help to get the nth field of the variable

Below is the format of my file which consist of 1)BSB 2)BSB/ADS 3)CIB 4)CIB/CRH 5)CIB/DCC 6)CIB/EMD 7)CIB/GDSPresentation 8)CIB/HCH 9)CIB/HSM 10)CIB/MCH 11)CIB/RCH 12)COB 13)DCI 14)DIB 15)DIB/H2H 16)DIB/HotelSync 17)DIB/UADBA (11 Replies)
Discussion started by: rohit22hamirpur
11 Replies

10. Shell Programming and Scripting

Awk adding a space between integer and the rest of the field

Hi, I have a problem where some of the records I need to process have the first address field as something like "10Walpole Street" where obviously I want it to be "10 Walpole Street". I know I need to somehow separate out the integer and probably form a new string variable, but I just don't... (5 Replies)
Discussion started by: jonathanm
5 Replies
Login or Register to Ask a Question