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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
charecter or number ganapati UNIX for Dummies Questions & Answers 1 01-02-2008 08:44 AM
Cutting a tab delimiter file vinod.thayil Shell Programming and Scripting 4 11-30-2007 03:38 PM
Cutting Columns and Moving in to a file Serious Sam Shell Programming and Scripting 3 10-22-2007 06:56 AM
Comapring files charecter by charecter using AWK/Shell Script evvander Shell Programming and Scripting 1 09-12-2007 05:44 AM
cut First charecter in any string rinku Shell Programming and Scripting 6 05-29-2007 07:23 AM

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 09-12-2006
mahabunta mahabunta is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 45
cutting columns if delimiter has more than one charecter

Hi,

My file looks like

abc$%sdfhs$%sdf$%sdfaf$%

here as seen delimiter is $%...now how cas i take out second field as cut command expect delimiter as single charecter only.....is there is any other way

thanks and regards
mahabunta
  #2 (permalink)  
Old 09-12-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
echo "abc$%sdfhs$%sdf$%sdfaf$%" | tr -s '$%' '  ' | cut -d" " -f3
I think you can not use two char as delimiter in cut. What you can do is translate that two char to single char and then cut it
  #3 (permalink)  
Old 09-12-2006
mahabunta mahabunta is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 45
thanks for reply.....

but is there is any other wat wirhout using tr command.......may be in AWk or any other method...
  #4 (permalink)  
Old 09-12-2006
mahabunta mahabunta is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 45
hi,

I guess it can be done using awk scripting....

say my file is delimited by ~%%~ and i need 6th field then following command will give me correct result.......

cat file | awk -F "~%%~" '{print $6}'

sandy
  #5 (permalink)  
Old 09-12-2006
BOFH BOFH is offline Forum Advisor  
Registered User
  
 

Join Date: Feb 2005
Location: Broomfield, CO
Posts: 406
Hmm, that didn't work in my test. Passing more than one character to -F just returned the entire line as argument $1.

Code:
awk -F"\$%" '{print $1}' file

abc$%sdfhs$%sdf$%sdfaf$%
abc$%sdfhs$%sdf$%sdfaf$%
abc$%sdfhs$%sdf$%sdfaf$%
abc$%sdfhs$%sdf$%sdfaf$%
abc$%sdfhs$%sdf$%sdfaf$%
abc$%sdfhs$%sdf$%sdfaf$%
abc$%sdfhs$%sdf$%sdfaf$%
You could use sed to change it:

Code:
sed -e "s/\$%/:/g" file | cut -f3 -d:

sdf
sdf
sdf
sdf
sdf
sdf
Or use tr as noted earlier:

Code:
cat files | tr -s "$%" ":" | cut -f3 -d:

sdf
sdf
sdf
sdf
sdf
sdf
It appears the $% is causing issues with the -F command. If I replace the $% with ", ", I can run

Code:
awk -F", " '{print $2}' files2

sdfhs
sdfhs
sdfhs
sdfhs
sdfhs
sdfhs
And it works. I also tried the $% delimiter in an awk script and it didn't work either. I tried escaping one and both characters without success.

Carl
  #6 (permalink)  
Old 09-12-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Escape the backslash, like this...
Code:
$ awk -F '\\$%' '{print $1}' file
abc
abc
abc
  #7 (permalink)  
Old 09-12-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,511
Quote:
Originally Posted by mahabunta
Hi,

My file looks like

abc$%sdfhs$%sdf$%sdfaf$%

here as seen delimiter is $%...now how cas i take out second field as cut command expect delimiter as single charecter only.....is there is any other way

thanks and regards
mahabunta
Just an alternative, in Python:
Code:
>>> line = "abc$%sdfhs$%sdf$%sdfaf$%"
>>> secondfield = line.split("$%")[1] #element 1 is second field
>>> print secondfield
sdfhs
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 01:06 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