The tag has no usage guidance.

learn more… | top users | synonyms

-3
votes
0answers
16 views

Removing intermediate line breaks in muliple columns except the last new line character [on hold]

Suppose If I have the data like this Col1|Col2|Col3 <br\> 123|abc\n<br\> xyz\n<br\> |abc\n<br\> def\n<br\> other rows<br\> <br\> In the above newline ...
4
votes
2answers
99 views

How to insert newlines into PATTERN when using fgrep / grep -F / grep --fixed-strings

When using fgrep, the man page says it will Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. In bash, what's the correct way to insert ...
3
votes
3answers
145 views

How do I remove newline character at the end of file?

Let me clear about newline character: $ echo Hello > file1 ; cat file1 Hello $ echo -n Hello > file2 ; cat file2 Hello$ Here you can see that file1 has newline character at the end whereas ...
0
votes
2answers
29 views

Shell script - blanks are not always recognized as such?

I'm confused on how bash interprets blanks while executing a script. In the end, I want a script that is fed by a csv file containing software used by an organisation and it should return the CVEs for ...
6
votes
1answer
37 views

How can I make `file` output line break type and encoding for all file types?

I often find myself in the need to check the encoding and the line break type of a file. The file utility seems to be a perfect fit. Unfortunately it doesn't output the desired information for all ...
1
vote
2answers
41 views

How to preserve the carriage return character (\n) when capture output of a command in a variable

As a simple example, I have a bunch of source code files. I want to store the "head" command output to a variable for all these files. I tried: output=$(head $file) but what happened is that this ...
0
votes
2answers
41 views

Check whether a file uses CRLF or LF to end lines [duplicate]

How to check whether lines in a text file end with CRLF or LF?
1
vote
1answer
70 views

How can I replace a literal \n with a newline character? (on OS X) [duplicate]

I have a script which pulls something out of my shell history and saves it to a file, but if there is a newline in the history entry it gets returned to me with a literal \n instead of the newline ...
1
vote
1answer
36 views

Why CR sequence (\r) getting entered in .vimrc file?

Please look at my '~/.vimrc' file below. :map g :w :map g :w See, the same line repeated. After writing 1st line, I pressed the "Enter" key. Now see the output of the od command below. ...
2
votes
1answer
30 views

Regex to match = followed by a newline so they both be deleted

I am working with the raw source content of a mail.app message in OSX, but results it gives me the text in quoted printable MIME Email encoding. so I need to remove all those strange characters to get ...
1
vote
1answer
539 views

How to fix “Hunk #1 FAILED at 1 (different line endings)” message?

I am trying to create a patch with the command git diff sourcefile >/var/lib/laymab/overlay/category/ebuild/files/thepatch.patch when I apply the patch, it gives me $ patch -v GNU patch 2.7.5 ...
1
vote
5answers
43 views

can't remove file with carriage returns

I have a file blahblah\r\n.txt that I want to remove but rm blahblah\r\n.txt does not work as I receive No such file or directory message. How to remove??
8
votes
6answers
402 views

Force newlines with cat wildcard printing

I want to use cat with wildcards in bash in order to print multiple small files (every file is one sentence) to standard output. However, the separate file contents are not separated by a newline, ...
1
vote
0answers
93 views

Grep can't find end of line in DOS format text file?

In Ubuntu I'm working on a C file that was originally created under Windows and then committed to source control. Vim shows the file format is "dos", which I gather just means it has CR/LF line ...
2
votes
3answers
95 views

uniq showing duplicate lines

$ grep home american.txt | sort | uniq A home and a country should leave us no more! ...
0
votes
4answers
141 views

How to delete the newline before EOF in a text/csv file via bash

Below is an example of the data I'm receiving in txt or csv file (seen in EmEditor): However, the final blank line is causing problems when uploading this data into my software. I need to have the ...
4
votes
1answer
137 views

bash prevent printf from interrupting another printf

I have the following test script. #!/bin/bash function foo { printf "Test line break: $1\nafter line break\n\n" } for VARIABLE in {1..30} do foo $VARIABLE & done wait Now I executed the ...
0
votes
1answer
35 views

How do I correctly add line ends with sed? [closed]

I have several sed statements that at one points uses newlines in the output with \n (Actually they are sed's using $' with \\\n's`). However subsequent sed operations that wish to operate on the end ...
1
vote
1answer
77 views

adb pull not accepting a variable as source, gives *' does not exist..* error

I'm trying to use $EXTERNAL_STORAGE in the adb pull command. I noticed that the variable has its scope defined in Android only and so it would not work successfully in adb pull ...
0
votes
1answer
94 views

How to replace \1\ with new line

I have a record like: "evSchema"\1\"UAT" "evSN"\1\"uadb" "evDirsep"\1\"/" "evRootPath"\1\"/work_area/APP_UAT/" "evSchema"\1\"RMS13" "evUser"\1\"STAGE" I want to replace \1\ with new line. I tried ...
1
vote
1answer
688 views

'while read line do' cause: “syntax error near unexpected token `done'” in Linux bash script

I have a shell script which is running fine on Solaris platform but not working on Linux platform. The Failing code snippet is as following: [...] while read line do insert_into_table="insert into ...
3
votes
1answer
4k views

Shell script error (: not found [No such file or directory]) [duplicate]

I'm using following script on linux server. And which is giving: : not found [No such file or directory] This is the script: # ------------------------------------------------------------------ # ...
3
votes
4answers
105 views

Not able to cat a string from a file under a string of another file

I have encountered a strange issue in concatenating the files using the cat command. I have two files with one string in each of them: file1: ABC file2: DEF Either I do cat file1 file2 or ...
1
vote
3answers
506 views

echo text after curl command on same line

#!/bin/bash echo "$(curl -s -I https://google.com|grep Server)" abc returns: abcer: gws and bash -x shows: ++ grep Server ++ curl -s -I https://google.com ' abco 'Server: gws abcer: gws but ...
0
votes
0answers
15 views

mkdir in shell script failing with \r [duplicate]

I have the following basic shell script: #!/bin/bash mkdir /var/lib/mysql/backups/test rm -r /var/lib/mysql/backups/* ROOTDIR="/var/lib/mysql/backups" TODAYDIR=`date +%Y%m%d` mkdir ...
3
votes
1answer
746 views

Grep doesn't match carriage return characters

I'm trying to find lines with the carriage return character, but I'm not getting the results I'd expect. I've whittled it down to this proof-of-concept: $ uname -a CYGWIN_NT-6.1 Aodh ...
6
votes
4answers
1k views

Add a newline into a filename with `mv`

It's a serious question. I test some awk scripts and I need files with a newline in their names. Is it possible to add a newline into a filename with mv? I now, I can do this with touch: touch ...
4
votes
1answer
88 views

Gedit displays text, but cat tells a different story

I am trying to sort a dictionary from Grady Ward's Moby and have encountered a bit of a problem. When I open it in gedit, I get: abaca×N abaciscus×N abacist×N aback×v abacli×p Abaco×N abactinal×A ...
0
votes
3answers
109 views

backup script to copy files by its extension

I have created script to copy .png files from one directory to another. Script is as follows: i="`cat /usr/local/app1/default.conf | grep -i values | sed -e 's/\values=//g' -e 's/,/ /g'`" for data ...
0
votes
3answers
3k views

How to detect end of line with sed

I'm looking for a way to only execute replacement when the last character is a newline, using sed. For instance: lettersAtEndOfLine is replaced, but this is not: lettersWithCharacterAfter& ...
2
votes
1answer
59 views

Trouble with horizontial merge of csv files under Cygwin

I have two csv files: test1.csv 1 2 3 4 test2.csv 6 7 8 9 I want to horizontally merge these two files. To do this I use paste -d , test1.csv test2.csv > paste.csv If I open this file in ...
5
votes
2answers
141 views

Elegant way to prevent command substitution from removing trailing newline

I'm customizing my zsh PROMPT and calling a function that may or may not echo a string based on the state of an environment variable: function my_info { [[ -n "$ENV_VAR"]] && echo "Some ...
5
votes
2answers
2k views

How to search for text in a file ignoring newlines?

I'd like to search for text that may be split over several lines in a file. A grep that would ignore line breaks and return the matching span of lines. e.g. I would be searching for is an example ...
1
vote
1answer
87 views

Reading input fields separated by spaces

How can I read in POSIX bash input like this: <name>,<tag1> <tag2> <tag3>… I tried while read line;do done but this wants newlines, all I have is spaces. (Is IFS solution? ...
1
vote
3answers
128 views

Remove special pattern ^M from script which got appended after FTP from windows to Unix

I send a windows file using FTP to an unix system and got appended ^M wherever a new line was intended, and I just want to remove them. One method which I can opt is to run dos2unix command. Can ...
0
votes
2answers
344 views

File transfer from AIX to Windows - CR and LF issues (Control Characters)

I have an issue transferring files between Unix(AIX) and Windows. I use the following mount command to mount a Windows folder on Unix. mount -v cifs -n /admin/@dmin -o ...
1
vote
2answers
102 views

Merge lines in file together from regex to “lineify” multiline log log files

Stadard unix command line tools (grep, cut, sed etc.) all work one line at a time. And nearly always, this is great. However I am trying to parse some postgresql slow query logs. Each entry has some ...
5
votes
5answers
1k views

How to replace a word with new line

I have a text file with following data and each row ends with |END|. T|somthing|something|END|T|something2|something2|END| I am tryig to replace |END| with \n new line with sed. sed ...
1
vote
5answers
90 views

keep out line break

I have some files with this structure: 2015-03-25 17:08:17 sysUpTimeInstance 93474;^M 1.ValueforState=2500 I want to replace the line break, and leave the third line with the second line, I mean, ...
1
vote
1answer
251 views

Switch-case block inside define keyword in a single logical line in a makefile

This is the code excerpt from ghc.mk, part of Haskell source compilation. I find it different, because the author has chosen to write one function block in a single line. Is it a common practice in ...
1
vote
2answers
59 views

Do I need “| xargs -n 1” to get around xargs' -I side-effect?

I was suprised to discover this: $ echo 1 2 3 4 5 | xargs -n 1 echo 1 2 3 4 5 $ echo 1 2 3 4 5 | xargs -n 1 -I FOO echo FOO 1 2 3 4 5 That is, using the -I flag has this side effect: Also, ...
8
votes
5answers
8k views

How to put a newline special character into a file using the echo command and redirection operator?

I would like to create a file by using the echo command and the redirection operator, the file should be made of a few lines. I tried to include a newline by "\n" inside the string: echo "first ...
0
votes
1answer
170 views

? appended to filename while copying from a ssh

I am using the command cp error.log error$HOSTNAME.log the command works properly while running it separately in a server, but if it is run as script which uses ssh I am getting a ? appended to the ...
2
votes
0answers
31 views

How to sort files by their dates into timestamped folders? [duplicate]

I want to sort about 2500 images every day into folders with a timestamp. So far I have this script but it's not working.... for x in *.jpg; do d=$(date -r "$x" +%Y-%m-%d) mkdir -p "$d" mv -- "$x" ...
1
vote
2answers
85 views

Some characters disappear after processing a text file

I've a file named addresses.txt : address1@domain.com address2@domain.com address3@domain.com I'd like to echo "address1@domain.com.html" using for loop. Here's what I did : cat addresses.txt | ...
6
votes
1answer
12k views

No such file or directory but I can see it!

I'm trying to run a python script, on a headless Raspberry PI using winSCP and get the following error message: Command '"./areadetect_movie_21.py"' failed with return code 127 and error message ...
1
vote
3answers
1k views

Shell script to delete multiple files

So, I have a file which contains a list of hundreds of files that need to be deleted from various directories. I figured the easiest method would be to create a batch file but I'm not having great ...
5
votes
2answers
2k views

sed: read whole file into pattern space without failing on single-line input

Reading a whole file into pattern space is useful for substituting newlines, &c. and there are many instances advising the following: sed ':a;N;$!ba; [commands...]' However, it fails if the ...
4
votes
3answers
2k views

sed fails to remove newline character

I've been using sed for quite some time but here is a quirk I came around with, which I am not able to resolve. Let me explain my problem with the actual case. Scene#1 printf "ls" | xclip ...
3
votes
1answer
79 views

Show exact number of CRLF occurrences in file

grep -c $'\r\n' file returns the exact same number as grep -c $'\n' file, it shows the number of LF in the file instead of the number of CRLF. (The file definitely does not contain that number of ...