Vishnu Nair
Vishnu Nair

Reputation: 1399

Arranging text in Linux

Let's say I have a file "example.txt" with the below content

user@computer ~ » cat example.txt

Output will be like              "aws"
                                 "aws-ec2"
                                 "aws-reinvent-2016"

Now I want to rearrange the output like below:

"aws", "aws-ec2", "aws-reinvent-2016"

How can I do it?

Upvotes: 0

Views: 28

Answers (1)

hek2mgl
hek2mgl

Reputation: 158000

You can use awk:

awk '{$1=$1}1' ORS=', ' example.txt

ORS=', ' set's the output record separator to ,. $1=$1 does not change anything in the line but still tells awk to reassemble the line using the new ORS. 1 will always evaluate to true and makes awk print the record.

Upvotes: 1

Related Questions