Visit Our UNIX and Linux User Community


Deleting newline and making output in single line with spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting newline and making output in single line with spaces
# 1  
Old 08-27-2013
Deleting newline and making output in single line with spaces

HI

I have a file line
vi Input
Code:
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460

When i do
awk -vORS="" '1' inputFile
i get 446447448449450451452453454455456457458459460

but i need output as
Code:
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460

Please help
# 2  
Old 08-27-2013
Using tr:
Code:
[user@host ~]$ cat file | tr '\n' ' '
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 [user@host ~]$

Old school:
Code:
[user@host ~]$ while read line; do printf "%s " $line; done < file
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 [user@host ~]$

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 08-27-2013
It worked
Code:
cat file | tr '\n' ' '

Smilie
# 4  
Old 08-27-2013
You just had to use the proper ORS

Code:
bash-3.2$ cat inputFile 
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
bash-3.2$ awk -v ORS=" " '1' inputFile
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 bash-3.2$

# 5  
Old 08-27-2013
@MR.Bean
It can be written shorter Smilie
Code:
awk 1 ORS=" " file

# 6  
Old 08-27-2013
Hello Jotne,

could you please explain how a new line or tab will work in
Code:
 ORS

, I have tried and it is giving the error as follows.


test file is:

Code:
$ cat small_data
09016ad2801ff702 09016ad2801ff703 09016ad280201300 09016ad280201302

Command used is:
Code:
$ awk 1 ORS="\\n" small_data

Output is as follows:
Code:
09016ad2801ff702 09016ad2801ff703 09016ad280201300 09016ad280201302


Thanks,
R. Singh
# 7  
Old 08-27-2013
What output did you expect?
Code:
echo "09016ad2801ff702 09016ad2801ff703 09016ad280201300 09016ad280201302" | awk 1 RS=" "
09016ad2801ff702
09016ad2801ff703
09016ad280201300
09016ad280201302

ORS= output record selector
RS = record selector (input)

Read this: 8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF, FILENAME, FNR (link removed)

Previous Thread | Next Thread
Test Your Knowledge in Computers #237
Difficulty: Easy
Paul Baran was the first to build a theoretical model for communication using packet switching.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

2. Shell Programming and Scripting

Making multiple lines as single line

Hi All, I have a spool file which as shown below. I want to make it as single line after every semicolon. In this case there should be 2 lines in vi editor. I am not used to use sed so could you guys please help me out ? exec spk_dba.sp_runsql('ALP','CREATE DATABASE LINK "TEST" CONNECT TO... (2 Replies)
Discussion started by: nicolas38
2 Replies

3. Shell Programming and Scripting

Joining multi-line output to a single line in a group

Hi, My Oracle query is returing below o/p ---------------------------------------------------------- Ins trnas value a lkp1 x a lkp1 y b lkp1 a b lkp2 x b lkp2 y ... (7 Replies)
Discussion started by: gvk25
7 Replies

4. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

consider the small piece of code while read line do echo $line done < example content of example file sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the output is like sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the... (4 Replies)
Discussion started by: Kesavan
4 Replies

5. Shell Programming and Scripting

Help substituting text in a file having a single line but no newline char

Hello, Need help substituting a particular word in a file having a single line but no newline character at the end. I was trying to use sed but it doesn't work probably because there is no newline char at the end of the line. $ cat hlq_detail /outputs/alvan23/PDFs/bills $ cat... (5 Replies)
Discussion started by: Shan_u2005
5 Replies

6. Shell Programming and Scripting

deleting blank line and row containing certain words in single sed command

Hi Is it possible to do the following in a single command /usr/xpg4/bin/sed -e '/rows selected/d' /aemu/CALLAUTO/callauto.txt > /aemu/CALLAUTO/callautonew.txt /usr/xpg4/bin/sed -e '/^$/d' /aemu/CALLAUTO/callautonew.txt > /aemu/CALLAUTO/callauto_new.txt exit (1 Reply)
Discussion started by: aemunathan
1 Replies

7. Shell Programming and Scripting

replace space or spaces in a line of a file with a single :

I am searching while I await a response to this so if it has been asked already I apologize. I have a file with lines in it that look like: bob johnson email@email.org I need it to look like: bob:johnson:email@email.org I am trying to use sed like this: sed -e 's/ /:/g' file >... (5 Replies)
Discussion started by: NewSolarisAdmin
5 Replies

8. Shell Programming and Scripting

single line input to multiple line output with sed

hey gents, I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Discussion started by: mitch
8 Replies

9. Shell Programming and Scripting

Deleting end line spaces for along file

How can i clear all space characteres for a long file at the end of each line? (3 Replies)
Discussion started by: osymad
3 Replies

10. Shell Programming and Scripting

Making multi line output appear on one line

Basically I wanna take grep output, EACH_OPTION_CHARGE: V033*, VMVM, 4.00, M EACH_OPTION_CHARGE: V040*, VMVM, 4.00, M EACH_OPTION_CHARGE: V042*, VMVM, 4.50, M EACH_OPTION_CHARGE: V043*, VMVM, 5.00, M EACH_OPTION_CHARGE: V050*, VMVM, 4.00, M EACH_OPTION_CHARGE: V052*,... (1 Reply)
Discussion started by: djsal
1 Replies

Featured Tech Videos