[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

UNIX cut -d command (Urgent please)

Posted on 2004-10-02
8
Medium Priority
?
518 Views
Last Modified: 2013-12-06
I have a text file that has one line and each field of the like are separated by two consecutive tabs. How can I extract each field?
I tried: $cat myfile.txt | cut -d"\t\t" -f0
this does not work...
0
Comment
Question by:tooki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 21

Assisted Solution

by:tfewster
tfewster earned 80 total points
ID: 12209856
Which version of Unix?
Try using ^I (Press Ctrl-V then Ctrl-I) instead of \t
0
 
LVL 11

Accepted Solution

by:
avizit earned 120 total points
ID: 12210506
you can use a trick by putting  a sed in between

try

sed -e 's/\t\t/:/g'  myfile.text | cut -d: -f1
0
 
LVL 48

Expert Comment

by:Tintin
ID: 12210918
The delimiter for the cut command must be a single character.

BTW, there is no field0 with cut, it starts at 1.

Certainly avizit's suggestion will work, but it would be helpful to see an actual example of your data, to see if there is a better way of extracting the information you need.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:tfewster
ID: 12211299
AIX, HP-UX & Linux don't allow multi-byte delimiters in `cut`; Solaris does, but I'm not sure if Solaris `cut` reads \t as a Tab char
0
 
LVL 48

Expert Comment

by:Tintin
ID: 12213545

Solaris cut (and probably all others) default delimiter is a tab.

Note that a multi-byte delimiter does not allow you to specify 2 or more characters as a delimiter.
0
 
LVL 4

Expert Comment

by:bytta
ID: 12245165
If you don't use any single tabs in your fields, just count {1,3,5,7,9} instead of {1,2,3,4,5} (note that the tirst field is -f1, not -f0)

Otherwise, a sed preprocessor (or similar) is a must...
0
 
LVL 2

Expert Comment

by:Troxalias
ID: 12284353
You can also try making this with awk. For example if you want the second field instead of cut, use awk '{print $2}' .
0
 
LVL 4

Expert Comment

by:bytta
ID: 12285329
sed is "awk for dummies"... A lot easier to learn and can to all the "normal" awk stuff, but missing the fancy features. I used a grep/cut/sed combination for years before I took the time to learn awk - and still prefer it...

Using awk works just as well, but does not provide anything extra for this case (except more typing ;o).
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question