problem with pipe operator


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers problem with pipe operator
# 1  
Old 06-23-2010
Question problem with pipe operator

hi i am having issues with extra pipe.
i have a data file and i need to remove the extra pipe in the(example 4th and 7thline) in datafile. there are many other line and filed like this which i need to remove from files. The sample data is below:
Code:
270 31|455004|24/03/2010|0001235|72
271 31|474012|13/04/2010|0001236|2.09
272 31|474013|13/04/2010|0001237|1.51
273 31|651003| 18/11/2008| |0
274 31|652005|14/01/2009|0001248|389
275 31|663018|18/01/2010|0001250|295
273 31|651003| 18/11/2008| |0

the output should be like:

Code:
270 31|455004|24/03/2010|0001235|72
271 31|474012|13/04/2010|0001236|2.09
272 31|474013|13/04/2010|0001237|1.51
273 31|651003|18/11/2008| |0
274 31|652005|14/01/2009|0001248|389
275 31|663018|18/01/2010|0001250|295

please help me as to how to remove this pipe and to format the datafile as above.

Last edited by Scott; 06-23-2010 at 09:46 AM.. Reason: Please use code tags
# 2  
Old 06-23-2010
Code:
[house@leonov] sed -i data.file -e 's/| |/|/g' -e 's/ //g'
[house@leonov] cat data.file
27031|455004|24/03/2010|0001235|72
27131|474012|13/04/2010|0001236|2.09
27231|474013|13/04/2010|0001237|1.51
27331|651003|18/11/2008|0
27431|652005|14/01/2009|0001248|389
27531|663018|18/01/2010|0001250|295
27331|651003|18/11/2008|0

# 3  
Old 06-24-2010
Question

thanks dr. the below query worked out. But still i am facing a problem in line 3rd, 6th etc(Prob o/p). How can we move |0 to the last col and get output like below:
31|474012|13/04/2010|0001236|2.09 or
31|474012|13/04/2010|(9 spaces)|2.09



prob:
31|474012|13/04/2010|0001236|2.09
31|474013|13/04/2010|0001237|1.51
31|651003|18/11/2008|0
31|652005|14/01/2009|0001248|389
31|663018|18/01/2010|0001250|295
31|651003|18/11/2008|0
# 4  
Old 06-24-2010
like this?
Code:
# sed -e 's/^\([0-9]* \)\(.*\)$/\2/' -e 's/ |*//g' infile
31|455004|24/03/2010|0001235|72
31|474012|13/04/2010|0001236|2.09
31|474013|13/04/2010|0001237|1.51
31|651003|18/11/2008|0
31|652005|14/01/2009|0001248|389
31|663018|18/01/2010|0001250|295
31|651003|18/11/2008|0

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to use pipe operator as simple character in text file?

Hello all, I have two files which are cmd and disk. `$cat cmd lsdev | grep -iw` `$cat disk hdisk2` Now I want to use the contents of both the files in a way such that `lsdev | grep -iw` command works for hdisk2 when I write the following script: `!#/bin/sh cmd1="$( sed -n... (4 Replies)
Discussion started by: ravi.trivedi
4 Replies

2. Shell Programming and Scripting

awk Help - Comparison Operator problem

Hi, I've tried searching through the forum but I've drawn a blank so i'm going to post here. I'm developing a number of checks on a CSV file, trying to find if any are greater than a max limit. I'm testing it by running it from a command line. The file I'm testing has 8 records. When I... (3 Replies)
Discussion started by: Tmart
3 Replies

3. Programming

Problem with STL's std::set container parameter to the operator << ()

Hi, I have this following code which gives me error when compiling. The problem is happening at the point where I create a const_iterator inside the overloaded insertion operator (i.e) operator << () function. The template argument version of set is not correct I guess. Could anyone please pitch... (3 Replies)
Discussion started by: royalibrahim
3 Replies

4. UNIX for Dummies Questions & Answers

Magic numbers '&' operator problem

Hello everyone, on the man page of "magic(5)" There is explanation "&, to specify that the value from the file must have set all of the bits that are set in the specified value" . My question is that what is the difference between '&' and equal operator '=' ? I tested it with file... (6 Replies)
Discussion started by: segmentation
6 Replies

5. Shell Programming and Scripting

The problem of pipe

Hi,guys: I want to use c to implement a pipe. For example: ps auxwww | grep fred | more I forked three child processes. Each is responsible for each command, and pipe to next one. for(i=0;i<2;i++) pipe(fd) if(child==1) // child 1 { close(1) dup2(fd,1) close(fd) }... (3 Replies)
Discussion started by: tomlee
3 Replies

6. UNIX for Dummies Questions & Answers

Problem unary operator expected

I get the following error ./get_NE05: line 42: while do echo ${STRING_NAME} J=1 if ; then EXT=0$I else EXT=$I fi while do echo $I-$J #calculating last occurrence OCCURRENCE=`grep -io "${STRING_NAME}"... (3 Replies)
Discussion started by: f_o_555
3 Replies

7. Shell Programming and Scripting

How can I use a pipe operator in a variable: OPTION="| command"?

I have a string of commands I am piping some data through and I want to allow command line switches to select which commands are used. I want to do something like this: OPTION="| command3" command1 -a -b c.txt | command2 -d -e $OPTION >result.txt I want to do it that way because OPTION may be... (1 Reply)
Discussion started by: KenJackson
1 Replies

8. Programming

Pipe problem

Could anyone tell me whats wrong whit this piping? the commands that they execute are correct. the command I am trying is ls|wc. Both processes go to the right if statement. for(i=0;i<argc;i++){ if(i==0&&argc>1){//first command if(pipe(pipa1)==-1) ... (2 Replies)
Discussion started by: isato
2 Replies

9. Shell Programming and Scripting

Problem with here doc operator in FTP script

Hello folks, I am facing a problem with the following korn shell script snippet: ftp -n -i -v <<EOF print -p open $CURR_HOST print -p user $USER $PASSWD print -p binary print -p cd /mydir/subdir/datadir print -p get $FILENAME print -p bye EOF exit It gives me the following... (3 Replies)
Discussion started by: Rajat
3 Replies

10. Programming

Problem about c++ new operator

#include <iostream.h> class test { private: int i; public: inline test(int m) { i = m; } inline int get_i() { return i; } }; int main() { test * a = new test(2); (3 Replies)
Discussion started by: xbjxbj
3 Replies
Login or Register to Ask a Question