Sponsored Content
Top Forums Shell Programming and Scripting differentiate between spaces and new-lines Post 302535537 by dips_ag on Friday 1st of July 2011 04:02:53 AM
Old 07-01-2011
differentiate between spaces and new-lines

Hi -

Here's the problem I'm encountering......My script logs in to remote FTP through password-less "sftp" and must get the list of sub-directories under a given path. I know many of the unix commands don't work in "sftp" login so I cannot know which one is a "directory" and which one is a "file". So I thought of copying the output of ls -l command in a file at local unix server and then going thru it to decide which ones are directories.

Having told my end of the story here's what I'm doing?
Code:
 
echo "ls -l $remote_ftp_path" > $batch_file
list_of_sub-dir=`sftp -b $batch_file $USER_ID@$IP_ADDRESS`

What happens?
Value of "list_of_sub-dir" variable has all the info about sub-dir, permissions, size, etc in one single line (as expected):
Code:
sftp> ls -l /remote/ftp/path drwxr-xr-x 2 user group 4096 Jun 13 15:55 remote_dir_1 -rw-r--r-- 1 user group 5090607 Jun 21 08:38 remote_file_1 -rw-r--r-- 1 user group 6917238 Jun 21 08:37 remote_file_2

and so on....

which I want in below format (after stripping "sftp> ls -l /remote/ftp/path")
Code:
 
drwxr-xr-x 2 user group 4096 Jun 13 15:55 remote_dir_1
-rw-r--r-- 1 user group 5090607 Jun 21 08:38 remote_file_1
-rw-r--r-- 1 user group 6917238 Jun 21 08:37 remote_file_2

Then I had a crazy idea of translating (only) spaces (and not new-lines) into commas
Code:
echo $list_of_sub-dir | tr " " ","

here's what I get instead
Code:
sftp>,ls,-l,/remote/ftp/path,drwxr-xr-x,2,user,group,4096,Jun,13,15:55,remote_dir_1,-rw-r--r--,1,user,group,5090607,Jun,21,08:38,remote_file_1,-rw-r--r--,1,user,group,6917238,Jun,21,08:37,remote_file_2

Can anyone please help me to get this? I really don't know what should I do to somehow preserve "\n" (new-lines) in the variable and not confuse them with "spaces"?!

-dips
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

delete blank lines or lines with spaces only

hi there i'm trying to delete blank lines and or lines with spaces only from a series of files in an directory. to do so, i'm using this: for files in `ls /users/myname/pesop* 2>/dev/null` do grep -v ^$ $files > newfile mv newfile $files done now, this works great for blank lines but... (3 Replies)
Discussion started by: vascobrito
3 Replies

2. Shell Programming and Scripting

How to remove plank spaces at the end of lines

Hello friends, I want to remove blank spaces at the end of lines. I use sed command to do this but it is not working correctly. sed ‘s/ $//’ file_name Can some body tell me what is the proper way to remove blank spaces at the end of a limes. Thanks, Mahesh Fernando. (3 Replies)
Discussion started by: maheshsri
3 Replies

3. Shell Programming and Scripting

Spaces in Lines for Variables

All, I am driving myself crazy over this one. I have run a find command against a volume on a nas. That returns a full listing of path and file name. This is an example of one line of output. I redirected the output of the find command to a file. ... (4 Replies)
Discussion started by: bubbwe
4 Replies

4. Shell Programming and Scripting

Deleting lines that contain spaces in a txt file

I need some help deleting lines in a file that contain spaces. Im sure awk or sed will work but i dont know much about those commands. Any help is appreciated :D (7 Replies)
Discussion started by: r04dw4rri0r
7 Replies

5. UNIX for Dummies Questions & Answers

using tr to print spaces between lines

hi forum i was wondering can you use tr to print out a file like this i see that there is no way you could do that i feel i see that there is no way you could do that i feel i see that there is no way you could do that i feel i see that there is no way you could do that i feel i see that... (2 Replies)
Discussion started by: ShinTec
2 Replies

6. Shell Programming and Scripting

Having a for loop read in lines with spaces?

Is this possible? I have a for loop in a shell script reading a list, but I want each line to be a loop, not each thing with a space. Here is the example: HOSTLIST="\ 1.2.3.4 serverA 1.2.3.5 serverB" for NBUHOST in `echo $HOSTLIST` do ssh ${SERVERNAME} "echo "${NBUHOST}"... (3 Replies)
Discussion started by: LordJezoX
3 Replies

7. Shell Programming and Scripting

remove spaces and lines that start with --

Is it possible to remove empty lines between >humid-sets (bold) and also humidset that start with -- (for ex: > humid3 | () : | (+) ) Thanx in advance Note: The humid sets will be in thousands and lines will be more than 100 thousand. input > humid1 | () : | (+)... (7 Replies)
Discussion started by: quincyjones
7 Replies

8. Shell Programming and Scripting

Reform Lines in File without blank lines and spaces

Hello All, I have a file with data as below. Each line consists of 21 fields. I am not able to load them back to the database. 50733339,"834","834 ","005010X279A1","N","Y","007977163","0001 ",30,"2110D ","EB ","EB007 ","2 ","Conditional Required Data Element Miss ing... (3 Replies)
Discussion started by: Praveenkulkarni
3 Replies

9. Shell Programming and Scripting

Spaces between the lines

How to get spaces between the two lines I have file File1 A.txt B.txt File2 C.txt D.txt Doing cat and appending to one file i.e file3 when i was doing append i need output like below File3 File1 (3 Replies)
Discussion started by: satish1222
3 Replies

10. Shell Programming and Scripting

Replacing certain positions in lines with spaces

Hello, I have a file with hundreds of lines. Now I need to replace positions 750-766 in each line (whatever there is there) with spaces... how can I do that? Which command to use? The result will be all the lines in the file will have spaces in positions 750-766. Thanks! (3 Replies)
Discussion started by: netrom
3 Replies
sftp-server(1M) 					  System Administration Commands					   sftp-server(1M)

NAME
sftp-server - SFTP server subsystem SYNOPSIS
/usr/lib/ssh/sftp-server DESCRIPTION
sftp-server implements the server side of the SSH File Transfer Protocol as defined in the IETF draft-ietf-secsh-filexfer. sftp-server is a subsystem for sshd(1M) and must not be run directly. There are no options or config settings. To enable the sftp-server subsystem for sshd add the following to /etc/ssh/sshd_config: Subsystem sftp /usr/lib/ssh/sftp-server See sshd_config(4) for a description of the format and contents of that file. There is no relationship between the protocol used by sftp-server and the FTP protocol (RFC 959) provided by in.ftpd. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. FILES
/usr/lib/sftp-server ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsshdu | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
sftp(1), ssh(1), ssh-add(1), ssh-keygen(1), sshd(1M), sshd_config(4), attributes(5) To view license terms, attribution, and copyright for OpenSSH, the default path is /var/sadm/pkg/SUNWsshdr/install/copyright. If the Solaris operating environment has been installed anywhere other than the default, modify the given path to access the file at the installed location. AUTHOR
Markus Friedl SunOS 5.10 30 Jul 2003 sftp-server(1M)
All times are GMT -4. The time now is 05:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy