Linked Questions
114 questions linked to/from Understanding "IFS= read -r line"
287
votes
5
answers
79k
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, ...
132
votes
6
answers
62k
views
Why is setting a variable before a command legal in bash?
I've just encountered several answers such as to parsing a delimited text file... that use the construct:
while IFS=, read xx yy zz;do
echo $xx $yy $zz
done < input_file
where the IFS variable ...
30
votes
7
answers
37k
views
`tail -f` until text is seen
I've got a CI server with a command-line interface that allows me to remotely kick-off a job (jenkins CI server and the jenkins-cli.jar tool).
After I kick the job off I tail -f the log (sorry for ...
39
votes
7
answers
35k
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 end ...
27
votes
3
answers
18k
views
Are files opened by processes loaded into RAM?
Commands, for instance sed, are programs and programs are codified logic inside a file and these files are somewhere on the hard disk. However when commands are being run, a copy of their files from ...
16
votes
6
answers
14k
views
If using while read loops for text processing in bash is bad...what should I do, then?
I guess this may be a naive question but I can't get my head around so I felt like asking...
I was searching for some solution to a problem, when I found this very interesting post about why is using [...
22
votes
2
answers
4k
views
Ask for a password in POSIX-compliant shell?
When I want to ask for a password in a bash script, I do that :
read -s
...but when I run bash in POSIX mode, with sh, the -s option is rejected:
$ read -s
sh: 1: read: Illegal option -s
How do I ...
6
votes
13
answers
2k
views
UNIX command to add comma and space
I have a file that looks like
$ cat IP
10.3.1.1
10.4.1.1
10.6.3.1
10.19.4.2
10.22.3.4
How do I make it look like:
$ cat IP
10.3.1.1, 10.4.1.1, 10.6.3.1, 10.19.4.2, 10.22.3.4
13
votes
7
answers
10k
views
How can I add random string for each line?
I'm trying to add random string for each line while running:
awk '{print "name" "'$ran'" "-"$0}' 'myfile'
Before that, the random string is generated:
ran="$(tr -dc '[:alnum:]' </dev/urandom | ...
7
votes
7
answers
25k
views
How to compare 2 strings in UNIX shell script? [duplicate]
I have a variable which stores a string, the output of a sed command.
I want to execute a set of commands only if this string value matches either of the 2 other strings.
I used the below code.
#! /...
17
votes
3
answers
11k
views
How to read different lines of a file to different variables?
I would like to read different lines of a text file to different variables. For example
input.txt:
line1 foo foobar bar
line2 bar
line3 foo
line4 foobar bar
I want this result to be stored in ...
15
votes
4
answers
4k
views
How to add new line between `ls -l` output
This is standard ls -l output.
user@linux:~$ ls -l
total 0
-rw-rw-r-- 1 user user 0 Nov 1 00:00 file01
-rw-rw-r-- 1 user user 0 Nov 1 00:00 file02
-rw-rw-r-- 1 user user 0 Nov 1 00:00 file03
...
10
votes
4
answers
2k
views
Performance of loop vs expansion
Need expert suggestions on below comparison:
Code Segment using loop:
for file in `cat large_file_list`
do
gzip -d $file
done
Code segment using simple expansion:
gzip -d `cat ...
9
votes
3
answers
49k
views
Find command - argument list too long
Oracle Linux 5.10
BASH shell
[oracle@src01]$ getconf ARG_MAX
131072
[oracle@srv01]$ ls -1 | wc -l
40496
#!/bin/bash
#
# delete files in /imr_report_repo that are older than 15-days
find /...