How to make all lines into 1 line?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to make all lines into 1 line?
# 1  
Old 06-13-2007
How to make all lines into 1 line?

I have a file listing IP addresses, 1 per line, such as:

1.2.3.4
3.4.5.6
12.13.14.15
7.8.9.6

I want all of the entries to be on the same line, and quoted, such as:

"1.2.3.4" "3.4.5.6" "12.13.14.15" "7.8.9.6"

I got the quotes on there in vi with ":%s/^/"/g" and "%s/$/"/g" ... is there an easier way?

Then I had to manually put them to 1 line by doing [del] [end] [space] about 25 times Smilie ... which was fine for this file that had ~25 entries, but in the future I may have to do it to a file with 1000+, so and awk or sed command that could do it would be great.

Thanks for your help.
# 2  
Old 06-13-2007
Code:
paste -s -d' ' input_file > output_file

# 3  
Old 06-13-2007
Given your input file format:

Code:
printf "\"%s\" " $(<file)

If you want the last new line:

Code:
printf "\"%s\" " $(<file);printf "\n"

# 4  
Old 06-13-2007
To put quotes before and after:
Code:
sed -e 's/^/"/' -e 's/$/"/' input_file > output_file

# 5  
Old 06-13-2007
Or:

Code:
ex - infile<<!
%s/.*/"&"
%j|x
!

# 6  
Old 06-13-2007
Code:
sed -i.bak 's/\(.*\)/"\1"/' input_file

If you want a newline at the end of the output file:
Code:
awk '{printf"\"%s\" ",$0}END{print}' input_file > output_file


Last edited by solfreak; 06-13-2007 at 05:54 PM..
# 7  
Old 06-13-2007
Quote:
Originally Posted by solfreak
awk '{printf"\"%s\" ",$0}END{print}' input_file > output_file
You meant:

Code:
... END{print ""}'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

3. Shell Programming and Scripting

Make Multile line is one line using window Perl

Hi All I have a .csv file which is showing data as ESP Client,ESP Engagement,Misc_Projects_120101,DEFAULT,HA,Unknown,No,Unknown,201704,4.1,Unknown,AAA,Collected-Done,"she,joy.",200111,Unknown,Full Time,,Delivery_DONE AMO,Approved,2012-12-03,2012-12-06,2012-12-06,"Occupied Hours ... (7 Replies)
Discussion started by: adisky123
7 Replies

4. Shell Programming and Scripting

Make all lines divisible by three

Hi, I need some help with the following: I need all lines in a file divisible by three, so for a file like this: 1 11 111 I want to add characters to make them all divisible by three (e.g. with an X): 1XX 11X 111 I would like to also ignore all lines that begin with the... (2 Replies)
Discussion started by: mikey11415
2 Replies

5. Shell Programming and Scripting

How to make duplicate lines

input tophr5:178975153-178982740:+ tophrX:14502176-14502376:+ output >tophr5:178975153-178982740:+ tophr5:178975153-178982740:+ >tophrX:14502176-14502376:+ tophrX:14502176-14502376:+ (2 Replies)
Discussion started by: quincyjones
2 Replies

6. UNIX for Dummies Questions & Answers

sed command, make multiple lines into one

:confused:Hi, I'm relativley new at unix so am having difficulties at the most basic of areas. I am trying using sed to make multiple lines into one line. For example, i would like: Mary had a little lamb to look like this Maryhadalittlelamb so far i have tried sed... (1 Reply)
Discussion started by: cavanac2
1 Replies

7. Shell Programming and Scripting

make multiple line containing a pattern into single line

I have the following data file. zz=aa azxc-1234 aa=aa zz=bb azxc-1234 bb=bb zz=cc azxc-1234 cc=cc zz=dd azxc-2345 dd=dd zz=ee azxc-2345 ee=ee zz=ff azxc-3456 ff=ff zz=gg azxc-4567 gg=gg zz=hh azxc-4567 hh=hh zz=ii azxc-4567 ii=ii I want to make 2nd field pattern matching multiple lines... (13 Replies)
Discussion started by: VTAWKVT
13 Replies

8. Shell Programming and Scripting

to make 2 lines into 1 line using awk

suppose i have a file AAAHHHHAHH AJJJJAAAAAA AJJJJJAAJJAK AJJAJJAJKKK the output suhd be AAAHHHHAHHAJJJJAAAAAAAJJJJJAAJJAKAJJAJJAJKKK (2 Replies)
Discussion started by: cdfd123
2 Replies

9. Shell Programming and Scripting

extract perticular lines and make them into speadsheet

Hi Masters, I knew this isn't a new issue, but couldn't find any similar threads. So, I have to bother you. Here is my input file (genomic data). The file has many sessions, each session seperated by //. Within eash session there is only one ID and GN line. ID 3HAO_HUMAN STANDARD; ... (4 Replies)
Discussion started by: mskcc
4 Replies

10. Shell Programming and Scripting

Make sed ignore lines

Hi I use sed in a script for severall changes in files. I whish one of the substitutions I made to be aplied to every line that has the word "scripts" with the exception for the ones that start with "rsh", wich I wish sed to ignore . Is this possible? If yes, how can I do it? The substitution... (2 Replies)
Discussion started by: Scarlos
2 Replies
Login or Register to Ask a Question