how to split special characters "|" using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to split special characters "|" using awk
# 1  
Old 05-22-2008
CPU & Memory how to split special characters "|" using awk

Hi friends

I need to splict special character "|" here.
Here is my script which giving error


LINE=INVTRAN|cd /home/msgGoogle

TraxFolderType=`awk -F"|" '{print $1}' $LINE`
filePath=`awk -F"|" '{print $2}' $LINE`
echo "TraxFolderType: "$TraxFolderType
echo "filePath :"$filePath


output:
------------
awk: cmd. line:1: fatal: cannot open file `INVTRAN|cd' for reading (No such file or directory)
awk: cmd. line:1: fatal: cannot open file `INVTRAN|cd' for reading (No such file or directory)
TraxFolderType:
filePath :


there is a space in 2nd string "cd /home/msgGoogle"
its giving problem
I need output like
TraxFolderType:INVTRAN
filePath :cd /home/msgGoogle

Please give me suggestions.

Thanks
Krishna
# 2  
Old 05-22-2008
Echo the line and pipe it to awk instead of read the line as a file:

Code:
TraxFolderType=`echo $LINE | awk -F"|" '{print $1}'`
filePath=`echo $LINE | awk -F"|" '{print $2}'`

Regards
# 3  
Old 05-22-2008
Hi

here it is treating LINE as a file name

try


TraxFolderType=`echo $LINE | awk -F"|" '{print $1}'`

filePath=`echo $LINE | awk -F"|" '{print $2}'`

Thanks
Penchal
# 4  
Old 05-22-2008
Thankyouuuuuuuuuuuuuu

its working
blindly iam doing my working without checking how iam writting code.
Thankyou
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to identify the special characters beyond the range of "[\x80-\xFF]"

I want to filter out the special character whose ascii value doesn't fall within the range "" . Example:� or Ć. So in that case is there any defined range which will filter out this characters. I can filter those which falls withing "" . Need to filter those special chracter which doesn't... (14 Replies)
Discussion started by: Abhijit Sen
14 Replies

2. UNIX for Dummies Questions & Answers

PuTTY displaying "special" characters

I'm not really sure which forum this question should go into, so I'm posting it here. I work with AIX and RHEL systems using PuTTY (Release 0.60_q1.129) from a Windows 7 workstation. Some of the files we get from z/OS use "special" characters as delimiters. These characters include Hex 18... (7 Replies)
Discussion started by: derndingle
7 Replies

3. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

4. Shell Programming and Scripting

Need HELP with AWK split. Need to check for "special characters" in string before splitting the file

Hi Experts. I'm stuck with the below AWK code where i'm trying to move the records containing any special characters in the last field to a bad file. awk -F, '{if ($NF ~ /^|^/) print >"goodfile";else print >"badfile"}' filename sample data 1,abc,def,1234,A * 2,bed,dec,342,* A ... (6 Replies)
Discussion started by: shell_boy23
6 Replies

5. 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

6. 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

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies

9. UNIX for Dummies Questions & Answers

perl split funciton - special character "/"

HI, I have a directory structure. /abc/def/ghi/ I want to store it into array. So that if I do a pop function on that array I can easily go to previous directory. But how can i split and store it. @Directory = split(/\//,$DirectoryVarialbe) That doest works. Any other escape sequence... (5 Replies)
Discussion started by: deepakwins
5 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