Quantcast
Channel: Changing linefeed by another character in bash - Unix & Linux Stack Exchange
Browsing all 9 articles
Browse latest View live

Answer by Rakesh Sharma for Changing linefeed by another character in bash

You can do this transformation multiple ways, some of them being:$ (head -n -1 - | tr \\n , ;cat -;) < inp$ perl -lp -0777e 'chop;tr/\n/,/' inp$ awk '$1=$1' FS="\n" RS= OFS=, inp$ awk '{ p = $0...

View Article



Answer by Thor for Changing linefeed by another character in bash

With awk:awk '$1=$1' RS= OFS=, infile

View Article

Answer by Praveen Kumar BS for Changing linefeed by another character in bash

Method1:perl -pe 's/\n/,/ unless eof' filenameoutput8600,22007,93509,9984,22146Method2(Using Python)#!/usr/bin/pythonm=open('file.txt','r')j=[]for i in m: j.append(i.strip())print...

View Article

Answer by Siva for Changing linefeed by another character in bash

Using GNU sed and assuming there's no POSIXLY_CORRECT variable in the environment or if there is, that the input has at least two lines: sed ':a;N;$!ba;s/\n/,/g' input.txtwe can't replace newline. But...

View Article

Answer by Michael Homer for Changing linefeed by another character in bash

If you want to do this in pure Bash, you can:ar=( $(<filename) )( IFS=, echo "${ar[*]}"> filename )This makes an array, ar, with the whitespace-separated words of filename as elements, and then...

View Article


Answer by αғsнιη for Changing linefeed by another character in bash

with single paste command:paste -d, -s infile-s makes the command to print lines in serial with -d, on comma separated.

View Article

Answer by Chris Davies for Changing linefeed by another character in bash

You can use trtr '\n' ,This will change every instance of \n to a comma, so you'll need to fix up the last one. Here's an examplecat >file.txt <<x86002200793509998422146xtr '\n' ,...

View Article

Answer by finswimmer for Changing linefeed by another character in bash

Use tr:$ <input.txt tr "\n"","8600,22007,93509,9984,22146,

View Article


Changing linefeed by another character in bash

I have a file like this one with ID over several lines but I need all records to be on the same line:86002200793509998422146to 8600,22007,93509,9984,22146Even if I can do it in vi with sed 1,$...

View Article

Browsing all 9 articles
Browse latest View live




Latest Images