What is the use of back slash \ in piping?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What is the use of back slash \ in piping?
# 1  
Old 12-04-2009
What is the use of back slash \ in piping?

Hi,

I had a script as below

Test_pipe.ksh

Code:
#!/usr/bin/ksh
echo `pwd`
id=`pwd | cut -d"/" -f2`
echo $id

result : /export/home
export

The above script executed sucessfully and I modified the script by placing a back slash "\" before cut command after pipe it is throwing an error as below

Code:
#!/usr/bin/ksh
echo `pwd`
id=`pwd | \ cut -d"/" -f2`
echo $id

/export/home/
Test_pipe.ksh[3]: cut: not found


My question is what is the use of back slash in pipe command.Where can I use "\" in piping.


Thanks,
Raju

Last edited by Neo; 12-04-2009 at 08:36 PM.. Reason: code tags
# 2  
Old 12-04-2009
Backslash is normally used to change the interpretation of the next character. In your case a space is loosing its separator capacity.
The error message means the command " cut" (with 4 characters) is not found which is correct.

One quite odd way to "fix" it would be to run:
Code:
ln -s $(whence cut) "$(dirname $(whence cut))/ cut"

One normal way of using backslash is for a continuation line, i.e. telling the shell to ignore the next new-line.
# 3  
Old 12-05-2009
Quote:
Originally Posted by somu_june
Hi,

I had a script as below

Test_pipe.ksh

Code:
#!/usr/bin/ksh
echo `pwd`
id=`pwd | cut -d"/" -f2`
echo $id


That is the same as, but much more inefficient than:

Code:
echo "$PWD"
id=${PWD#*/}
id=${id%%/*}
echo "$id"

Quote:

result : /export/home
export

The above script executed sucessfully and I modified the script by placing a back slash "\" before cut command after pipe it is throwing an error as below

Code:
#!/usr/bin/ksh
echo `pwd`
id=`pwd | \ cut -d"/" -f2`
echo $id


Why did you put it there? What were you trying to accomplish?
Quote:

/export/home/
Test_pipe.ksh[3]: cut: not found


My question is what is the use of back slash in pipe command.

The backslash has nothing to do with the pipe command (in your example or anywhere else).

Quote:
Where can I use "\" in piping.

Why do you want to use the backslash in piping? What are you trying to achieve?

If you don't know what it does, don't use it.
# 4  
Old 12-05-2009
'\' is used for telling shell to remove the special features associated with a character.

For eg: %s/search/replace/g

Here '/' is used to separate the pattern to be searched and pattern to be replaced.
But if you have '/' in the pattern to be searched, you have to dereference it like below.

%s/\/export/\/import/g

This will replace /export with /import. So I used '\' to remove the special feature of '/'.
# 5  
Old 12-05-2009
Hi all,

Thanks for your replies. My aim is to get the Time stamp portion from a file using grep and cut command.

My input file inputfile_jobstart_grep contains data like below in a single line

DBsetup DFModify Infilter Uvchange Uvdelete Uvfile Uvread Uvtlconvert Uvwrite cat uvwrite basic block catalog cdict claccount clear.file cname conf.file Job start time=2009-12-05 11:00:00

I want to get Job start time from the input file like 2009-12-05 11:00:00

I tried using below command

echo `cat inputfile_jobstart_grep | \ grep "^[ ]*Jobstart time" | \ cut -f2 -d\=`

but the result is
bash: grep: command not found
bash: cut: command not found


In above command i used caret "^" for matching beging of the line and "*" to match zero or more preceding. As Tene mentioned I'm using back slah "\" to remove special features associated with character like cat and equal sign character in file. But I'm getting below error.

Can some body help me to understand why I'm getting above errors and how can I resolve the above error


Thanks,
Raju
# 6  
Old 12-05-2009
Quote:
Originally Posted by somu_june
Hi all,

Thanks for your replies. My aim is to get the Time stamp portion from a file using grep and cut command.

My input file inputfile_jobstart_grep contains data like below in a single line

DBsetup DFModify Infilter Uvchange Uvdelete Uvfile Uvread Uvtlconvert Uvwrite cat uvwrite basic block catalog cdict claccount clear.file cname conf.file Job start time=2009-12-05 11:00:00

I want to get Job start time from the input file like 2009-12-05 11:00:00

I tried using below command

echo `cat inputfile_jobstart_grep | \ grep "^[ ]*Jobstart time" | \ cut -f2 -d\=`

but the result is
bash: grep: command not found
bash: cut: command not found

Why are you using backslashes?

Remove them and all will be well.
Quote:


In above command i used caret "^" for matching beging of the line and "*" to match zero or more preceding. As Tene mentioned I'm using back slah "\" to remove special features associated with character like cat and equal sign character in file. But I'm getting below error.

You are removing the special feature from the space that follows the slash so that the shell sees the command as ' cut' not 'cut', and ' grep' not 'grep'.
# 7  
Old 12-05-2009
Hi Johnson ,

I tried the command removing backslashes

`cat inputfile_jobstart_grep | grep "^[ ]*Jobstart time" | cut -f2 -d =`


but I'm not getting any output or result from the command on the screen.


Thanks,
Raju
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Slash delimiter

I have a log file which on field $11 there is sth like: /A/B/C and I want to extract the last part which is C. for space delimiter I used: awk '{print $2 " " $5 ";" $7 ";" $9 ";" $11}' and had no problem. but dont know how to extract the 3rd part of the slash delimiter. That would be... (6 Replies)
Discussion started by: frhling
6 Replies

2. Shell Programming and Scripting

Using sed to append backward slash before forward slash

Hi all, I need to know way of inserting backward slash before forward slash. My problem is that i need to supply directory path as an argument while invoking cshell script. This argument is further used in script (i.e. sed is used to insert this path in some file). So i need to place \ in front... (2 Replies)
Discussion started by: sarbjit
2 Replies

3. UNIX for Advanced & Expert Users

Substitute single backward-slash with the double backward-slash

Hi, I have a path like this c:\test\sample\programs, i need to change thiis to c:\\test\\sample\\programs. How to perform this? I tried tr command but it didn't help me. Thanks Vijayan (3 Replies)
Discussion started by: mvictorvijayan
3 Replies

4. IP Networking

Back-to-Back Connection using HBAs

Hi every body, Is it possible to connect two servers Back-to-Back (Point-to-Point) using HBA adapters & using Fiber. Note it is direct connection & there is no switches between the servers. I'm concern about using HBA adapters, it is possible or not. Thanks in advance. :) (3 Replies)
Discussion started by: aldowsary
3 Replies

5. Shell Programming and Scripting

About \ (Back slash)

Hi All, print "path/executable_file parameters" \ > path/file1 print "path/executable_file parameters" \ > path/file2 print "path/executable_file parameters" \ > path/file3 chmod 775 path/file1 \ path/file2 \ ... (7 Replies)
Discussion started by: Arunprasad
7 Replies

6. Shell Programming and Scripting

Replace the last slash alone

Hi All, Can you please help me with the below issue. I want only the last slash to be replaced with space. 06/05/2008/EDED_FD_BDCD_ABCD_123 06/05/2008 EDED_FD_BDCD_ABCD_123 (3 Replies)
Discussion started by: christineida
3 Replies

7. AIX

back to back printing in UNIX

Hi , Can you suggest me how to back to back printing in UNIX? Is there any way? Kindly advise. Regards Vijaya Amirtha Raj (3 Replies)
Discussion started by: amirthraj_12
3 Replies

8. Shell Programming and Scripting

ftp username with back slash

Hi, My ftp user name is in the format US\tere I tried using escape characters US\\tere but it is not working fine please advice.. sam (1 Reply)
Discussion started by: sam99
1 Replies

9. Shell Programming and Scripting

awk slash

I have configuration file(master.cnf), that contents are: VER1LOG /src/ver1/log VER2LOG /src/ver2/log APPLOG /src/sys/apps/log APPCONF /src/sys/apps/conf APPBIN /src/sys/apps/bin my shell script is as below mylog=sys/apps awk "/$mylog/" master.cnf awk: syntax error Context is: >>> ... (6 Replies)
Discussion started by: McLan
6 Replies
Login or Register to Ask a Question