Convertin IP adresses from a column to a raw + add a comma between addresses


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convertin IP adresses from a column to a raw + add a comma between addresses
# 1  
Old 08-22-2012
Converting IP adresses from a column to a raw + add a comma between addresses

Hi all,

I have a list of IP addresses in a column in a text file name ipaddress.txt
Code:
192.168.0.1
192.168.0.2
192.168.0.5
192.168.0.4
192.168.0.5

I would like to convert ipaddress.txt to have the following thing :
Code:
192.168.0.1, 192.168.0.2, 192.168.0.3,192.168.0.4,192.168.0.5

I know how to do it with a spreadsheet but it would very useful for me to be able to do it in CLI.

I think I should use sed and awk commands but I haven't find a solution up to now

Your help will be very appreciated.

Regards,

Olivier

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by oliv66; 08-22-2012 at 04:30 PM..
# 2  
Old 08-22-2012
Code:
xargs<ipaddress.txt>new_ipaddress.txt

e.g.
Code:
lo4:/export/home/vbe/.test $ cat titi
192.168.0.1
192.168.0.2
192.168.0.5
192.168.0.4
192.168.0.5
lo4:/export/home/vbe/.test $ xargs<titi
192.168.0.1 192.168.0.2 192.168.0.5 192.168.0.4 192.168.0.5
lo4:/export/home/vbe/.test $

# 3  
Old 08-22-2012
one way:
Code:
awk '1' ORS=, myFile| sed 's/,$/\n/'
or
xargs < myFile | sed 's/ /,/g'

This User Gave Thanks to vgersh99 For This Post:
# 4  
Old 08-22-2012
Thanks vgersh99, I missed the commas separated ( dificult to do 2 things at a time...)
This User Gave Thanks to vbe For This Post:
# 5  
Old 08-22-2012
many thanks to both of you for your quick response. you have the right answer for my issue.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bring values in the second column into single line (comma sep) for uniq value in the first column

I want to bring values in the second column into single line for uniq value in the first column. My input jvm01, Web 2.0 Feature Pack Library jvm01, IBM WebSphere JAX-RS jvm01, Custom01 Shared Library jvm02, Web 2.0 Feature Pack Library jvm02, IBM WebSphere JAX-RS jvm03, Web 2.0 Feature... (10 Replies)
Discussion started by: kchinnam
10 Replies

2. Shell Programming and Scripting

How to use regex on particular column (Removing comma from particular column)?

Hi, I have pipe separated file which contains some data having comma(,) in it. I want to remove the comma(,) only from particular column without changing data in other columns. Below is the sample data file, I want to remove the comma(,) only from 5th column. $ cat file1 ABC | DEF, HIJ|... (6 Replies)
Discussion started by: Prathmesh
6 Replies

3. Shell Programming and Scripting

Insert comma in place of column

Hi all, I have a file in which I have to insert commna between entries of 2 column and createa new file separated by commas not a columns if input is FHIT Adenosine Monotungstate Not Available CS Trifluoroacetonyl Coenzyme A Not Available Theo expected output is ... (5 Replies)
Discussion started by: manigrover
5 Replies

4. Shell Programming and Scripting

Substituting comma "," for dot "." in a specific column when comma"," is a delimiter

Hi, I'm dealing with an issue and losing a lot of hours figuring out how i would solve this. I have an input file which looks like this: ('BLABLA +200-GRS','Serviço ','TarifaçãoServiço','wap.bla.us.0000000121',2985,0,55,' de conversão em escada','Dia','Domingos') ('BLABLA +200-GRR','Serviço... (6 Replies)
Discussion started by: poliver
6 Replies

5. Shell Programming and Scripting

Replace pipe <|> with comma <,> in a column

Hi All Gurus, I need to replace a pipe <|> with a comma <,> in a few columns with pipe delimited file. The column name are fixed for the replacement of comma <,>. For below example, Col3, Col6 and Col8 are columns need to replace with comma <,> if any pipe encountered. example:... (14 Replies)
Discussion started by: agathaeleanor
14 Replies

6. Shell Programming and Scripting

rearrange the column names with comma as column delimiter

Hi, I am new to shell scripting, i have requirement can any one help me out in this regrads, in directory i have file like invoice1.txt, invoice2.txt in each file i have fixed number of columns, 62 in number but they are randomly arranged.like for first file invoice1.txt can have columns... (5 Replies)
Discussion started by: madhav62
5 Replies

7. Shell Programming and Scripting

subtitute value of certain raw and column with sed

Dear All, For example the content of data.txt file is: 1 1 23 2 1 42 3 2 52 4 2 62 5 1 77 6 1 88 7 2 99 8 1 100 Could I substitute 2 in second column with 1 using sed commad so that the data will be change as follow ? 1 1 23 2 1 42 ... (1 Reply)
Discussion started by: ariesto
1 Replies

8. Shell Programming and Scripting

convertin in to upper case

write a shell script that accepts one or more file name as arguments and converts all of them to uppercase,provided they exist in the current directory:b::b::b: (2 Replies)
Discussion started by: shawz
2 Replies
Login or Register to Ask a Question