![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| charecter or number | ganapati | UNIX for Dummies Questions & Answers | 1 | 01-02-2008 05:44 AM |
| Cutting a tab delimiter file | vinod.thayil | Shell Programming and Scripting | 4 | 11-30-2007 12:38 PM |
| Cutting Columns and Moving in to a file | Serious Sam | Shell Programming and Scripting | 3 | 10-22-2007 03:56 AM |
| Comapring files charecter by charecter using AWK/Shell Script | evvander | Shell Programming and Scripting | 1 | 09-12-2007 02:44 AM |
| cut First charecter in any string | rinku | Shell Programming and Scripting | 6 | 05-29-2007 04:23 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
echo "abc$%sdfhs$%sdf$%sdfaf$%" | tr -s '$%' ' ' | cut -d" " -f3 |
|
#3
|
|||
|
|||
|
thanks for reply.....
but is there is any other wat wirhout using tr command.......may be in AWk or any other method... |
|
#4
|
|||
|
|||
|
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
|
|||
|
|||
|
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$%
Code:
sed -e "s/\$%/:/g" file | cut -f3 -d: sdf sdf sdf sdf sdf sdf Code:
cat files | tr -s "$%" ":" | cut -f3 -d: sdf sdf sdf sdf sdf sdf Code:
awk -F", " '{print $2}' files2
sdfhs
sdfhs
sdfhs
sdfhs
sdfhs
sdfhs
Carl |
|
#6
|
||||
|
||||
|
Escape the backslash, like this...
Code:
$ awk -F '\\$%' '{print $1}' file
abc
abc
abc
|
|
#7
|
|||
|
|||
|
Quote:
Code:
>>> line = "abc$%sdfhs$%sdf$%sdfaf$%"
>>> secondfield = line.split("$%")[1] #element 1 is second field
>>> print secondfield
sdfhs
|
|||
| Google The UNIX and Linux Forums |