How to cut a line with the delimeter "pipe symbol"

Hi

I am unable to cut a line with the delimeter as a pipe symbol "|"
COuld you please help me ?
below is the code i am using right now
************
for i in `cat xyz`
do
source=`echo $i | cut -f 1 -d |`
echo $source
done
*********
Error i am recieving while exceuting the above scripts is as below where "abcd" is the above script name
./abcd: command substitution: line 2: syntax error: unexpected end of file
./abcd: command substitution: line 2: syntax error: unexpected end of file

Thanks in Advance,
Tasha

source=`echo $i | cut -d "|" -f1`

cheers,
Devaraj Takhellambam

This should work. Of course, "ps -ef | grep pmon" is only for testing. Replace it with $i (as in your script).

 
$ echo "ps -ef | grep pmon" | cut -d '|' -f1
ps -ef
$
 

HTH,:cool:

Regards,

Praveen

When i used this stmt,
`echo "$i" | cut -d '|' -f1`
the output is blank...

The other one is giving me an error.

Could you all please give me any other code if possible ?

Thanks in advance

also echo $i first to see what is its content.
please use a double " around the delimeter as I mentioned earlier

source=`echo $i | cut -d "|" -f1`

cheers,
devaraj Takhellambam

Hi Thank you !!

The problem is solved..
I missed type the word "source" that is the reason it was giving a blank o/p
Now it is working fine..
source=`echo "$i" | cut -d '|' -f1`

Thank you very Much !!!!!
Tasha_T

You can go for a simple awk as follows, as well

awk -F"|" '{ print $1}' file_name

# cat xyz
A|B|C
# cat xyz | cut -f1 -d \|
A
#
Or the quick Version :slight_smile: :
# cut -f1 -d \| < xyz

Kind regards,
Ren�