Linked Questions

0
votes
1answer
112 views

Turn multiple line into one liner with custom separator [duplicate]

Trivial question. What is the most elegant function myfunction that allows to produce the following output? # myfunction "a b c d" a%0Db%0Dc%0Dd%0D
3
votes
1answer
59 views

How to prefix backslash to output [duplicate]

This is my input file. 3400,2 3400,27 3400,DC 3400,TF 5600,KA 5600,KN 5600,TF 0313,EX 0313,EY 0313,EZ 0313,FD 0313,FE 0313,JB 0313,JC 0313,KG 0313,T8 I want my output to be 400,2\|3400,27\|3400,DC\|...
206
votes
4answers
43k views

Why is using a shell loop to process text considered bad practice?

Is using a while loop to process text generally considered bad practice in POSIX shells? As St├ęphane Chazelas pointed out, some of the reasons for not using shell loop are conceptual, reliability, ...
22
votes
17answers
5k views

How to find line with least characters

I am writing a shell script, using any general UNIX commands. I have to retrieve the line that has the least characters (whitespace included). There can be up to around 20 lines. I know I can use ...
18
votes
3answers
30k views

Merge jq output into a comma separated string [duplicate]

I am trying to curl some URL which returns a json file, then I want to parse hosts from it and create a comma separated string. I have the first part working curl -s -u "admin:admin" -H "X-...
15
votes
8answers
16k views

Turning separate lines into a comma separated list with quoted entries

I have the following data (a list of R packages parsed from a Rmarkdown file), that I want to turn into a list I can pass to R to install: d3heatmap data.table ggplot2 htmltools htmlwidgets ...
13
votes
5answers
4k views

What's the best way to take a segment out of a text file?

What's a good way of extracting say, lines 20 -45 out of a huge text file. Non-interactively of course!
6
votes
12answers
1k views

How to collapse consecutive numbers into ranges?

Given a sorted input file (or command output) that contains unique numbers, one per line, I would like to collapse all runs of consecutive numbers into ranges such that n n+1 ... n+m becomes n,n+m ...
6
votes
1answer
5k views

custom delimiter for unix find results

I want to use find to find some files, and return all files as a single line (without newline characters), and a custom delimiter between the files. So for example the result for three files would be ...
3
votes
2answers
217 views

Filter text from each file and turn it into a list of comma-separated values

I'm trying to extract some information from multiple files and create a csv-type file. Until now I got the extracting and writing to file part working but don't know how I could add a comma between ...
1
vote
1answer
194 views

Change “\n” by “|” between 2 patterns (patterns excluded) with sed

I'd like to change \n by | between 2 patterns (patterns excluded) with sed. I have a file with an adress sequence several time : Adress: 1540 Broadway New York NY 10036 United-states ### I would ...