![]() |
|
|
|
|
|||||||
| 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 |
| replace space with delimiter in whole file -perl | meghana | Shell Programming and Scripting | 11 | 02-19-2008 06:35 PM |
| delete a field along with delimiter in the whole file | dsravan | Shell Programming and Scripting | 5 | 11-01-2007 10:40 PM |
| remove space in front or end of each field | happyv | Shell Programming and Scripting | 6 | 03-21-2007 11:05 PM |
| Set a variable field delimiter using awk | Klashxx | Shell Programming and Scripting | 2 | 03-24-2006 06:10 AM |
| How to parse a text file with \034 as field and \035 as end of message delimiter? | indianya | Shell Programming and Scripting | 1 | 08-26-2005 06:20 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Is there some way to specify a field delimiter for a space or more (like " "+) ?
For example: In the following string, I like to reach value '30695' what field delimiter I should say? Thank you. -rw-rw-r-- 2 uphamtn staff 30695 May 12 09:23 howToDo ---------------- I appreciate your response very much. Actually, my example string has one or MORE spaces but when it showed up on this page, it squezzes 2+ spaces into 1 space. In addition, I tried to use 'cut' command to get the size value of files from the output of 'ls -ltr' command. Ex. ls -ltr | cut -d" " -f5 . This command will work if there is only one space separated between fields. And it won't work in my string because it has either one or more spaces between fields. Any idea ? Thanks. ====== IT WORKED, THANKS A LOT. Last edited by uphamtn; 05-15-2003 at 01:35 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
I like to reach value '30695' what field delimiter I should say?
-rw-rw-r-- 2 uphamtn staff 30695 May 12 09:23 howToDo get your list and pipe it to awk - ll | awk -F" " '{print $5}' will print a list at position 5. positions are delimited by a space ( -F" "). I think the default delimiter for awk is a space. |
|
#3
|
||||
|
||||
|
Could you explain more about what you're trying to do?
Here's one way to extract the value: Code:
var="-rw-rw-r-- 2 uphamtn staff 30695 May 12 09:23 howToDo"
echo $var | awk '{ print $5 }'
|
|
#4
|
||||
|
||||
|
The awk command will handle one space or 10 spaces, so the amount of space on your line shouldn't matter.. if you're gonna add the values up, see this post.
FYI, it screws up the continuity of the post when you start editing your previous posts after replies have been made. |
||||
| Google The UNIX and Linux Forums |