The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
perl split funciton - special character "/" deepakwins UNIX for Dummies Questions & Answers 5 02-08-2008 12:19 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
split the string "Setview: arv-temp-view" amitrajvarma Shell Programming and Scripting 2 10-11-2007 05:14 AM
deleting newline characters but not the "true" \n character caddyjoe77 Shell Programming and Scripting 1 08-15-2007 10:21 PM
Perl - split with "|" lumdev Shell Programming and Scripting 3 02-04-2007 02:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-22-2008
krishna9 krishna9 is offline
Registered User
  
 

Join Date: May 2008
Posts: 9
Arrow 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 (permalink)  
Old 05-22-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,294
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 (permalink)  
Old 05-22-2008
penchal_boddu penchal_boddu is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 127
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 (permalink)  
Old 05-22-2008
krishna9 krishna9 is offline
Registered User
  
 

Join Date: May 2008
Posts: 9
Thankyouuuuuuuuuuuuuu

its working
blindly iam doing my working without checking how iam writting code.
Thankyou
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0