how to read double consecutive space in filename for bash shell


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to read double consecutive space in filename for bash shell
# 1  
Old 07-17-2007
how to read double consecutive space in filename for bash shell

Hello,

Im using cygwin app which we use the bash shell for scripting.
Im trying to read a filename with consecutive spaces on the filename
ex: filename<space><space>1.txt

ls -lrt filename<space><space>1.txt is working but when I pull that from a file and place it into variable. it reads only as single space: filename<space>1.txt

ex:
cat samp.txt
output:
1:filename<space><space>2.txt
2:filename<space><space>1.txt
3:filename<space><space>3.txt

var1=`cat samp.txt |sed -n -2p |awk '{print $NF}'`
echo $var1
output:
filename<space>1.txt

Please advice how to read double consecutive spaces. Is there any escape characters?
# 2  
Old 07-17-2007
James,
Space has a special meaning for the shell as a field separator and
it treats multiple spaces as one.
You have two ways of displaying the two spaces:
Code:
IFS='@'
cat input_file | \
while read mLine
do
  echo "mLine = <"$mLine">"
done

or
Code:
cat input_file | \
while read mLine
do
  echo "mLine = <$mLine>"
done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing consecutive double quotes

Hi I have a .csv file and when opened in notepad looks like this gggg,nnnn,"last,first","llll""",nnn So, Here I would like the ouput as below gggg,nnnn,"last,first","llll",nnn i.e replace all two double quotes into one. How could I do that? This file is being processed by another... (5 Replies)
Discussion started by: dnat
5 Replies

2. UNIX for Beginners Questions & Answers

sed command to replace consecutive double quotes

I need to replace consecutive double quotes in a csv file, the data in the file is enclosed in double quotes but there are some places where the quotes are repeating Example is below Incoming data is : "Pacific Region"|"PNG"|"Jimmy""|""| Need output as: "Pacific... (10 Replies)
Discussion started by: abhilashnair
10 Replies

3. Shell Programming and Scripting

Bash only count consecutive days

I was wondering how I would go around to do this. This is an example of my output Sun Aug 21 2016 03:00:00, BLAH Mon Aug 22 2016 03:54:00, BLAH Tue Aug 23 2016 04:22:11, BLAH Thu Aug 25 2016 05:00:00, BLAH Now what I would like to do is only count CONSECUTIVE days so in the... (1 Reply)
Discussion started by: rodriguesm
1 Replies

4. UNIX for Dummies Questions & Answers

Sed- Replace space in filename by a \

`echo $file | sed 's/ / /g'` Hey guys I want help in converting the spaces in my file names to '\ ' . Example: UK maps --> UK\ maps Could someone please help me. I have tried the following sequences already (none of them work): 1)s/ /\ /g 2)s/ /\\ /g 3)s/ /\\\ /g Can someone... (7 Replies)
Discussion started by: INNSAV1
7 Replies

5. Shell Programming and Scripting

Help with Disk Space script in bash shell

Hi Guys, I'm a newb at shell scripting and successfully attempted a small disk space script (victory!!) but i'm wondering whether it actually takes into consideration KB,MB,GB. Please take a look at the script and advise. ##script to check if file sys has reached threshold. ... (3 Replies)
Discussion started by: Irishboy24
3 Replies

6. UNIX for Dummies Questions & Answers

filename with white space

our user creates a text file with a white space on the filename. this same file is transfered to unix via automation tool. i have a korn shell script that reads these files on a input directory and connects to oracle database to run the oracle procedures which will load the data from each of the... (2 Replies)
Discussion started by: wtolentino
2 Replies

7. Shell Programming and Scripting

BASH Shell script - help with read

Hi all, I'm sure this is quite a simple problem, but i'm completely new to shell scripting, so bare with me. Having problems with the read command. Here's what I have: read -rp "Command to execute: " the_command ... ... echo "$the_command" ... ... eval "$the_command" Now, say, for... (8 Replies)
Discussion started by: Justin Alvarez
8 Replies

8. Shell Programming and Scripting

How to use while loop in bash shell to read a file with 4 lines of gap

Hi , I am currently using the while loop in bash shell, as follows. while read line do echo $line done < file.txt However, i want to use the while loop on file.txt, which will read the file with 4 lines of gap. Ex- if file.txt is a file of 100 lines, then i want to use the loop such... (3 Replies)
Discussion started by: jitendriya.dash
3 Replies

9. Shell Programming and Scripting

Consecutive spaces within input being converted to single space

I'm reading from a file that is semi-colon delimited. One of the fields contains 2 spaces separating the first and last name (4th field in - "JOHN<space><space> DOE"): e.g. TORONTO;ONTARIO;1 YONGE STREET;JOHN DOE;CANADA When I read this record and either echo/print to screen or write to... (4 Replies)
Discussion started by: NinersFan
4 Replies

10. UNIX for Dummies Questions & Answers

filename that starts with a space

I accidentally started a filename with a spce and I can not get rid of it. Any words of advice? (6 Replies)
Discussion started by: noobie_doo
6 Replies
Login or Register to Ask a Question

Featured Tech Videos