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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to cut a line with the delimeter "pipe symbol"
# 1  
Old 04-30-2009
Network 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
# 2  
Old 04-30-2009
Code:
source=`echo $i | cut -d "|" -f1`

cheers,
Devaraj Takhellambam
# 3  
Old 04-30-2009
This should work. Of course, "ps -ef | grep pmon" is only for testing. Replace it with $i (as in your script).

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

HTH,Smilie

Regards,

Praveen
# 4  
Old 04-30-2009
Thank you , but still the problem is not solved

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
# 5  
Old 04-30-2009
also echo $i first to see what is its content.
please use a double " around the delimeter as I mentioned earlier

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

cheers,
devaraj Takhellambam
# 6  
Old 04-30-2009
Problem resolved...

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
# 7  
Old 04-30-2009
You can go for a simple awk as follows, as well

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

2. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

3. Shell Programming and Scripting

Extract string between two delimeter " "

I want a string between two delimeter like " " from below file and also send send output to the file. Input File, 2007_08_07_IA-0100-014_"January".PDF 2007_08_07_IA-0100-031_"January February March April June July".PDF 2008-02-28_KR-1022-003_"January febuary march april may".CSV ... (0 Replies)
Discussion started by: Pratik Majithia
0 Replies

4. Shell Programming and Scripting

How to allign output data in UNIX that is separated with a pipe "|" symbol ?

Experts , In the given output of the log file, the 2nd field that is separated by "|" pipe is not aligned well due to the uneven data length, I would like it to align the 2nd column with 37 length (that is disturbed in the output) including the pipe . The two pepe "|" would be in a aligned way... (2 Replies)
Discussion started by: rveri
2 Replies

5. UNIX for Dummies Questions & Answers

use cut or awk to print line after "/bin"

Hello all, i am trying to use cut or awk to make my below lines to From $ ps -ef|grep tns|grep -v grep |grep LISTENER_TEST|awk '{print $9}' /oracle/ORAHOME/test/112/bin/tnslsnr to /oracle/ORAHOME/test/112 how can this be achieved ? so basically anything before "/bin" (3 Replies)
Discussion started by: abdul.irfan2
3 Replies

6. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

help for saving vertical datas to horizontal with "awk" or "cut"

hi, i have a file having datas like that ./a.txt 12344 12345 12346 12347 ..... ..... ... i want to save this datas to another file like that ./b.txt 12344 12345 12346 12347 ... ... ... i think awk can make this but how? :) waiting for ur help. (3 Replies)
Discussion started by: mercury
3 Replies

9. Shell Programming and Scripting

How to cut a file using " ", but fields can be separated with more than one " "

Hello, let's say I have a text file: word11 word12 word13 word21 word22 word23 word31 word32 word33 and I want to put the second field of each line into a list: set list = `cut -d" " -f2 ${1}` and I use space (" ") as a delimiter, only that there's a catch: there can be more than... (12 Replies)
Discussion started by: shira
12 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question