This is because the for list splits on IFS that defaults to space,tab,NL.
So a space is treated like a NL.
You can explicitly set IFS to only NL
But it is more clever to use read that reads lines
And it splits into distinct variables by IFS (space and tabs only; it will never see an NL because of the read)
This User Gave Thanks to MadeInGermany For This Post:
If I have a data file containing entries like-> abc abc:123
and I use a for loop:
for I in `cat data-file`
do
echo $I
done
the output would contain 2 lines -> abc.... and abc:123
but I want it to be on only one line. How can I do this?
thanks (1 Reply)
Hi Experts,
I am finding the performance of cat command is very wierd, it is taking more time to merge the files into a single file. We have a situation where we would be merging more than 100 files into a single file, but with cat command it is running slow. I tried doing with paste, join... (13 Replies)
Hi I have a simple code that I want to execute.
out=out.txt
for f in `cat list.txt | head -1`; do
echo $f >> $out
echo "sleep 5" >> $out
done
cat list.txt | head -1
wget -q -O - 'http://test.com:15100/cgi-bin/search
cat out.txt
wget
sleep 5
-q
sleep 5
-O (10 Replies)
Hello,
So I sorted my file as I was supposed to:
sort -n -r -k 2 -k 1 file1 | uniq > file2
and when I wrote
> cat file2
in the command line, I got what I was expecting, but in the script itself
...
sort -n -r -k 2 -k 1 averages | uniq > temp
cat file2
It wrote a whole... (21 Replies)
I have list of files in my current directory
abc.txt
123.csv
234.csv
245.csv
145.csv
123_ex_c.sv
I don't want to open first and last file. i.e (abc.txt and 123_ex_csv)
I tried
cat *.csv, but it won't work.
Can anyone tell me the proper regex only in cat
Thanks
Pritish
... (2 Replies)
ok..
so problem is:
I have a file that reads:
cat 123
1 and 2
3 and 4
5 and 6
I was using for loops to run through this information.
Code:
for i in `cat 123`
do
echo $i
done
shouldn't the output come as
1 and 2 (3 Replies)
We have shell script (in ksh) which reads the records from a csv file line by line and does some operation. We have below command to read the file (CSV has the absolute path of files stored on a server something like SER/IMP/TEST/2010/12/123465.1).
P_FILES=`cat $P_BATCH_FILE`
for i in $P_FILES... (2 Replies)
Hi all,
I need to create loop script to read full line and append a variable to each line.
cat file
I need the output like below
10.0.0.1,136 1 24 048800 id N4 No_Light
10.0.0.1,137 1 25 048900 id N4 No_Light
10.0.0.1,140 1 28 048c00 id N4 No_Light
10.0.0.1,262 1 38 048e80... (13 Replies)
limit.csv data
--------------
5600050 38Nhava
400077 27Bomay
rate.txt data
-------------
38NhaVA
27BomaY
27Bomay
below is my script:
for i in `cat limit.csv`
do
b=`awk '{print $1}' $i` (4 Replies)
I have a script to do a couple simple but repetitive commands on files that are provided to us. One of the things is to get rid of the line feeds. This is the section that is causing problems, i even cut this section into its own file to make sure nothing else was affecting it.
#!/usr/bin/bash... (4 Replies)