Visit Our UNIX and Linux User Community


Treating Strings with spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Treating Strings with spaces
# 1  
Old 11-04-2009
Treating Strings with spaces

I have a file list.txt which has a list of file names with spaces between the file names like
/emptydir/file 1
how do i browse through the list.txt displaying the filenames. Almost all the file names in list.txt have space between them.This file list.txt is formed by using the find statement to find all the files in a given directory. Now i need to traverse through the list.txt and print each of the filenames in it. If someone has a suggestion to display the filenames without redirecting the output to the file list.txt, please let me know. That is much appreciated. Thanks in advance folks.

Last edited by kinny; 11-04-2009 at 10:56 AM..
# 2  
Old 11-04-2009
Code:
cat /emptydir/file\ 1

to see all the content of all of the files:

Code:
cat *

It isn't exactly clear to me what you mean....
# 3  
Old 11-04-2009
Hi Scruti Thanks for the reply.

I think i misquoted. I want to print the names of the files and not cat the file itself. Hope this clears the confusion.
# 4  
Old 11-04-2009
Hi,

You just want to get the file names ? Can the spaces be deleted ? If yes, can you try `tr -s " " ""` and remove spaces ? Will that help your purpose ?
# 5  
Old 11-04-2009
Something like this then?
Code:
while read i ; do
  ls -ld "$i"
done<list.txt

# 6  
Old 11-04-2009
To just display the filenames without putting the list into a file called list.txt .
Code:
find /emptydir/ -type f -print

Or if you then wanted to do something with each filename. Note the double quotes to preserve spaces.
Code:
find /emptydir/ -type f -print | while read filename
do
          echo "${filename}"
done


Previous Thread | Next Thread
Test Your Knowledge in Computers #107
Difficulty: Easy
Each Unix kernel subsystem has key features like concurrency, virtual memory, paging, and a virtual file system.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Can I combine below mentioned grep commands using OR (when searching strings having spaces)

Command 1: $script | grep 'Write to ECC( SSID=MARGIN)' Command 2: $script | grep 'is not greater than existing logical processing' The above commands run my script and search the mentioned strings but I do not want to run my script twice. It is increasing run time. Can someone tell me... (3 Replies)
Discussion started by: Tanu
3 Replies

2. Shell Programming and Scripting

Concat strings without spaces...

Hello, I have a very travial question....when i run the below script...how can i change my script that will give me an output pf "this is log_vp1" ....i dont want any spaces between log_vp and 1 or any other character...i know i can set a variable for 1(lets say num is the var) and then do... (2 Replies)
Discussion started by: crazy_max
2 Replies

3. Shell Programming and Scripting

Comparison treating strings as zero integers

I'm trying to write a bash script to perform basic arithmetic operations but I want to run a comparison on the arguments first to check that they're a number greater than zero. I want an error to pop up if the arguments args aren't >= 0 so I have: if ! ]; then echo "bad number: $1" fi ... (14 Replies)
Discussion started by: TierAngst
14 Replies

4. Shell Programming and Scripting

Treating string as date ?

Is there a way to treat a string as date and compare it to the current date? lets assum inpu lik $ cat myfile Name Last login ************************** Sara 2/13/2012 kalpeer 2/15/2012 ygemici 2/14/2012 we want to display the name who logged in during the last #... (4 Replies)
Discussion started by: Sara_84
4 Replies

5. Shell Programming and Scripting

Replace spaces between strings in a line with tab

Hi All I am having problem in substitution of any number of spaces, or a combination of space and tab in between strings in the lines of text file. Is there any way out in Perl? Please help me. e.g., Say the input is in the following format:- XX yyy zzz... (1 Reply)
Discussion started by: my_Perl
1 Replies

6. Programming

Concatenating array of strings into one string separated by spaces

Hi, Well as the title says, I have an array of strings (delimited by null). The length of the array is variable and length of each string is variable as well. What I need is one huge string with the original strings in the array separated by spaces. For example is an array is such that array... (12 Replies)
Discussion started by: newhere
12 Replies

7. Shell Programming and Scripting

TRAP treating

Hi, I'm looking for a script that receives the traps from a windows machine and treate them. For exemple just write a line in a file on UNIX server. Can you help me ? Thank you. (2 Replies)
Discussion started by: big123456
2 Replies

8. Shell Programming and Scripting

ksh: Comparing strings that contain spaces and working with substrings

Forgive me. I am very new to kornshell scripts. The simplest things stop me dead in my tracks. Here are two such examples. I want to save the first 19 characters of the following string to a variable. "Operation Completed and blah blah blah" I know this works (from another thread): ... (2 Replies)
Discussion started by: nancylt723
2 Replies

9. UNIX for Dummies Questions & Answers

Append strings with filler spaces

Hi I am looping through the contents of a file as follows cat file |while read inrec do echo $inrec >> $TMP done (obviously this isn't all i am doing as it would be pointless but for the sake of the problem this is the important bit) The file has fields which are separated by... (1 Reply)
Discussion started by: handak9
1 Replies

Featured Tech Videos