Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [newlines]

The tag has no usage guidance.

3
votes
1answer
53 views

Newline character produced by `echo`, is it always there when using no options, regardless of shell?

Although I have read Stephane's answer concentrated on basically all aspects of echo vs printf, I am unsure if it also answers my question, which stands: The newline character produced by echo, is it ...
0
votes
0answers
39 views

Grep across multilines [duplicate]

I need to grep text with new lines included. Example of code: 1. text==","Timestamp":1554799403148,"text":null}} 2. 3. 2019-04-09 04:43:23.7822|text 4. 5. 2019-04-09 04:43:23.9706|text|GuId:...
7
votes
1answer
133 views

Newlines in BSD sed vs gsed

The sed, which comes with FreeBSD 11.2 p7, gives: $ seq 10 | sed 'N; l; D; p' 1$ 2$ 2$ 3$ 3$ 4$ 4$ 5$ 5$ 6$ 6$ 7$ 7$ 8$ 8$ 9$ 9$ 10$ While gsed (GNU sed 4.7) gives for the same script: $ seq 10 | ...
1
vote
1answer
57 views

Recursively converting Windows files to Unix files

I have a PHP application with is located on Linux with multiple directories (and sub-directories) and many PHP, JS, HTML, CSS, etc files. Many of the files have Windows EOL control characters and I ...
8
votes
1answer
390 views

Why don't I see the difference between two different files in insert mode in vim?

Let's create two files: $ echo -n 'test' > test.txt $ wc test.txt 0 1 4 test.txt The file test.txt doesn't contain the trailing newline. $ echo 'test' > test_n.txt $ wc test_n.txt 1 1 5 ...
-6
votes
1answer
66 views

bash loop all files in directory, then loop lines of each file

I have urls1.txt urls2.txt urls3.txt And so on. How can I loop all files in this directory then loop each line of these files?
0
votes
1answer
102 views

How to replace double new line with single using tr?

Given a text, $ cat a.txt Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at magna sed libero accumsan ultrices. Proin varius tortor risus, at pulvinar quam auctor vitae. Etiam iaculis ...
3
votes
2answers
321 views

Could PATH contain newlines?

It is known that a path could contain newlines in any of its components. Should we conclude then that the environment variable $PATH could contain newlines ? If so, how to split the $PATH into its ...
7
votes
1answer
427 views

Shells with the ability to treat `\r` as a whitespace character

As a personal project, I'm trying to write a script to clean up some of the extraneous files that ship with Windows 10 that runs under Cygwin. I'd like the script to be copy and paste-able, which ...
2
votes
2answers
77 views

How can I get less to display \n as a newline?

I have some files containing \n newlines that I am viewing with less. I would like to be able to have less display those newlines as actual newlines. For example an array: Array\n(\n [Color] =&...
0
votes
3answers
338 views

Read arguments separated by newline

I have a script and I receive data from stdin as an argument separated by newlines say I have string1,string2 string3,string4 And I want to take sperately string1,string2 and string3,string4. But I ...
4
votes
4answers
578 views

Assign variable using multiple lines

I have a function f(){ echo 777 } and a variable to which I assign the "return value" of the function. x=$(f) Very concise! However, in my real code, the variable and function names are quite ...
0
votes
1answer
35 views

sed alters windows line endings unintentionally. How can I avoid that?

I am developing in linux a portable application, in which I wanted to remove trailing spaces from some source files, which have windows style line endings. The line endings should not be changed to ...
0
votes
1answer
488 views

How to add a newline in xargs

I'm trying to write a command to capture every license in the linux OS (kali) and associate it with the correct package. The basic idea is that you search /usr/share/doc recursively for "copyright" ...
1
vote
1answer
143 views

How to correctly store a newline character in a (POSIX) shell variable? [duplicate]

update attempt to clarify more, using an example, does the following shell commands: SHELLVARIABLE="1st line, 2nd line, 3rd line, " printf '%s' "$SHELLVARIABLE" generate this output: 1st line,<...
0
votes
1answer
37 views

Awk of string followed by '\n'

I try to parse a plain text config file A.conf with the following content: bitrate 500000 use_can 1 I want to use the number behind bitrate to setup a CAN-interface with the appropriate bitrate. ...
0
votes
2answers
124 views

sed - preserve newline when writing to new file

I have files containing data. This data sometimes has artifacts in them which I need to get rid of. An example line looks like this: @@@@@@@@@@DK2018.4.24_0:0:0.200985,0.88,0.35,0.49,13.52,248.3 Or ...
-1
votes
2answers
53 views

i want to replace ^M\n part by space in a csv file using sed command in linux

I want to replace ^M\n part by space in a CSV file using sed command in Linux..... I used sed 's/\n/ /g' but it is only replacing \ and not the other part..... To be more descriptive, i am using ...
3
votes
2answers
492 views

GNU grep check if input contains a LF character

I test content of a set of data files whether they contain at least one of a set of characters which consists of printing and non-printing characters. My last issue is detecting whether the file ...
2
votes
1answer
40 views

collect content from multiple lines into one single output

assume I have a text file with lots of content including lines like these: ... ... ABCD1 1234 12345 XYZ foo bar 1234597890 ... DEFG2 5678 56789 XYZ foo bar 0987654321 ... ... and I need to ...
7
votes
5answers
720 views

sed only removing \n provided by sed '=' command

I created a file using: printf 'this is \n not is \n is is \n this biz' > file2 when I try to remove all \n(newline) it only remove sed's own inserted number's newline sed '=' file2 | sed 'N; s/...
9
votes
2answers
406 views

Why does `sudo -i` but not `sudo` remove newline characters? [duplicate]

What can explain the examples below and how do I fix this, preferably without heavy quoting acrobatics? I am using the $n to simulate multiple line command strings, just in case it distracts you from ...
9
votes
1answer
620 views

When printing a variable that contains newlines, why is the last newline stripped? [duplicate]

Contents of file.txt (no weirdness, text file as defined by POSIX) iguana gecko anole Sample script: #!/bin/sh string="$(cat file.txt)" printf '%s' "$string" Sample output: [coolguy@somemachine ...
1
vote
1answer
803 views

How to grep for literal '..'

I am parsing a file using grep and the output on screen contains newline, as here: $ grep 'gene' sequence.gb gene 89..1483 /gene="non-structural protein" ...
2
votes
2answers
137 views

Make bash dos-eol tolerant [closed]

It happens when I want to compile some Linux kernel that somehow I end up with such messages: .../kernel-source/scripts/mkmakefile: line 5: $'\r': command not found That is because the file is with ...
1
vote
2answers
1k views

Carriage return, LineFeed and Sed behaviour

I need to understand why sed is able to work for 1) and not for 2). Please do not post me any alternative solutions. I have already found them on this forum. I just need to understand the behavior of ...
3
votes
1answer
535 views

replace newline with nul

bash, osx mavericks I want to replace the LF character (hex=0A) with NUL (hex=00) in a txt file. can I use grep or tr or something to accomplish this? I've been using bbedit to replace them, but I'd ...
3
votes
2answers
7k views

Split single line into multiple lines, Newline character missing for all the lines in input file [duplicate]

I there a way to split single line into multiple lines with 3 columns. New line characters are missing at the end of all the lines in the file. I tried using awk, but it is splitting each column as ...
0
votes
2answers
59 views

How to remove both type newlines using only bash

The variable v has \n and, hm, another type newline?? v='ab\n cd ef ' printf '%b' "$v" ab cd ef printf '%s' "$v" ab\n cd ef printf '%s' "$v" | xxd 00000000: 6162 5c6e 2063 640a 2065 660a ...
0
votes
1answer
491 views

How to remove a special character in my curl output using grep,sed or awk

I'm trying to remove \r\n in the output of my curl my code is: curl -s -u ian.guinto:W0lfg@ng131994 --request GET --url 'https://jira.toro.io/rest/api/2/issue/OJTSYSAD-829/comment' -H "Content-Type: ...
-2
votes
1answer
34 views

Is there a another way to display a part of a line using sed

so i have a file called test.txt that contain the following lines. The first school , located at random at 0000 The second school , located at random at 1000 The third school , located at random at ...
3
votes
3answers
1k views

Redirect content under a new line (without further syntax or arguments)

I tried these ways to append content to a file: printf "\nsource ~/script.sh" >> /etc/bash.bashrc echo -e "\nsource ~/script.sh" >> /etc/bash.bashrc cat >> "/etc/bash.bashrc" <&...
7
votes
2answers
903 views

Test if variable contains newline (POSIX)

I know that some shells accept this kind of test: t() { [[ $var == *$'\n'* ]] && res=yes || res=no printf '%s ' "$res"; } var='ab cd' t var='abcd' t echo on execution: $ bash ./...
1
vote
1answer
475 views

How to printf literal characters from/to file in bash?

I want to filter a file by character (for the purpose of removing invalid xml characters which I cannot control the generation of) but I cannot seem to even be able to copy individual characters from ...
11
votes
2answers
2k views

Why does wc <<<“$string” show a one-byte-longer length than printf “$string” | wc?

Accidentially, I found out that wc counts differently depending on how it gets the input from bash: $ s='hello' $ wc -m <<<"$s" 6 $ wc -c <<<"$s" 6 $ printf '%s' "$s" | wc -m 5 $ ...
2
votes
2answers
638 views

how to separate line using awk

How can I separate the line as below in a csv file: (12,'hello','this girl,is lovely(adorable \r\n actually)',goodbye),(13,'hello','this fruit,is super tasty (sweet actually)',goodbye) to the below ...
0
votes
1answer
53 views

How to create a folder from a string in a file?

I have a script which do some conversions. To be able to save the results in a specific folder i have a file (csv file) the script is reading and from there it takes a string (I do it now with echo/...
9
votes
6answers
5k views

Read a line-oriented file which may not end with a newline

I have a file named /tmp/urlFile where each line represents a url. I am trying to read from the file as follows: cat "/tmp/urlFile" | while read url do echo $url done If the last line doesn't ...
2
votes
0answers
259 views

I think printf broke my newlines in terminal [duplicate]

After running a bash script, my (gnome-)terminal ended up printing each new line where the last one ended (but on the next row). I think it was printf that broke things, since it works if I replace ...
1
vote
1answer
31 views

Better shell solution when blank lines may be piped to wc

I have code that does something like this: #!/bin/sh CONTENTS=$(cat "somefile") RELEVANT_LINES=$(echo "$CONTENTS" | grep -E "SEARCHEXPR") COUNT=$(echo "$RELEVANT_LINES" | wc -l) I hit an annoyance ...
0
votes
3answers
172 views

line breaks in a dos linebreaks file?

I have dos file by default populating with CRLF as line breakers. But , some times I get LF instead of CRLF. I need to figure where exactly change is occurring for line breaks.And I don't want to ...
2
votes
1answer
76 views

Differences in whitespaces between bash script and interactive shell

Please advice why this happens. from a Linux bash shell: ps PID TTY TIME CMD 20406 pts/0 00:00:01 bash 26896 pts/0 00:00:00 ps I run the follwing str="a b c d" printf "%s\n" ` echo ...
86
votes
4answers
16k views

Why does Linux use LF as the newline character?

As far as I know, every operating system has a different way to mark the end of line (EOL) character. Commercial operating systems use carriage return for EOL (carriage return and line feed on Windows,...
3
votes
2answers
777 views

Print all complete lines of file

How do I print all complete lines of a file? By 'complete' I mean only the ones that end with newline character. grep treats EOF as line delimiter, so grep '^.*$' file will print the last line even if ...
1
vote
1answer
208 views

using find, sed, and xargs to fix filenames from data recovery on a mac

Okay, I'm going in circles. I'm using this command find . -print0 -name '*.1.*' | sed -e 'p;s/\.1//' | xargs -0 -n2 mv To try and rename hundreds of files that had ".1." added just before the file ...
4
votes
2answers
332 views

Bash: Why is alias after newline ignored when run remotely?

In Bash I run: alias myalias='echo foo echo bar echo baz' myalias which returns: foo bar baz But: ssh localhost "shopt -s expand_aliases &>/dev/null; alias myalias='echo foo echo bar echo ...
0
votes
1answer
323 views

Command substitution is adding a newline?

I have a script that queries the device architecture from an android device, and uses that in a path to push a file to the device. The code is similar to this: ARCH=$(adb shell getprop ro.product....
1
vote
1answer
548 views

Newline in command line argument in tcsh

In bash, it is easy to pass newline as command line argument: foo 'this is a command line argument with newlines' However, if I try the same in tcsh, it complains about a missing '. How can I type ...
-2
votes
1answer
508 views

Replace a string with sentence containing multiple newline characters [duplicate]

I am trying to replace string with a sentence or paragraph contacting multiple newline characters using shell script. Replacement string will be generated run-time. eg: sed /string_to_be_replaced/...
1
vote
2answers
157 views

Insert Newlines into serial stream before writing to text file

I have an RFID reader which sends the Unique ID of the RFID tag to the serial port of my linux (raspberry pi) box every time it gets a successful read. The problem is that it is sending it without any ...