cut usage in bash


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cut usage in bash
# 1  
Old 11-17-2008
cut usage in bash

Hello,
Could you put some light on this:
Code:
> echo "ref_categorie=test" | cut -c1-15-
test
> echo "ref_categorie=test" | cut -c1-14-
=test
echo "ref_categorie=test" | cut -c15-
test
echo "ref_categorie=test" | cut -c15 
t
>

It's executed on AIX if that matters. The man page is not very verbose. What I've figured out myself is that cut -c removes chars from string (which is stated in manpage actuallySmilie ). I've found a few examples via Google. So after -c is the chars position I suppose. Also it looks like that without the trailing dash cut just prints the char at this position.
Here is what I don't understand:
1) "ref_categorie=" is 14 chars, why -c14- leaves also the '='?
2) What's the difference between -c15- and -c1-15- ? They do the same in my case, but maybe there is something that I'm missing.
Thank you very much for your help!
# 2  
Old 11-17-2008
Hammer & Screwdriver

Three basic formats of the -c option in the cut command

-c15 will cut character position 15
-c1-15 will cut character positions 1 thru 15
-c15- will cut from character position 15 to the end

I would think that your first two examples would be giving some kind of syntax error as they are not standard or correct.

Lastly, you can specify more character positions than simply one range. See the following
-c1-5,10-11,21-
cut positions 1 through 5, 10 through 11, and from 21 to the end

Last edited by joeyg; 11-17-2008 at 10:04 AM..
# 3  
Old 11-17-2008
It does make sense now. Thank you very much, joeyg.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using :<<cut / cut to comment out block of bash script

I am using : << cut / cut to comment out block of code. Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines. The "warning " is at last line of script. done < results 169 echo "END read all positioning parameters" 170... (8 Replies)
Discussion started by: annacreek
8 Replies

2. Shell Programming and Scripting

Detail on For loop for multiple file input and bash variable usage

Dear mentors, I just need little explanation regarding for loop to give input to awk script for file in `ls *.txt |sort -t"_" -k2n,2`; do awk script $file done which sorts file in order, and will input one after another file in order to awk script suppose if I have to input 2 or... (4 Replies)
Discussion started by: Akshay Hegde
4 Replies

3. Shell Programming and Scripting

Usage cut command

cut command usages ?? i have a file named test contents : srikanth hyd 123 vinoth chn 234 vijay chn 345 hemanth hyd 456 $cut -f2 test should display: hyd chn chn hyd but am gettg full file?? (2 Replies)
Discussion started by: Diddy
2 Replies

4. Shell Programming and Scripting

Bash, if or usage

Trying to find a better way to check $REMOTE_USER against a list of permiited users. The only way I can get it to work is to do a bunch of or statements shown here. My list of permitted users will be a dozen or so, I was hoping to list them in a variable or a file. if || ; then (Load this page)... (4 Replies)
Discussion started by: numele
4 Replies

5. Shell Programming and Scripting

Cut out string in bash script

Hi all, I'm trying to extract string from variable in BASH. That's probably trivial for grep but I couldn't figure it out. I want to get name, there's sometimes digit after it, but it should be left out. STRING=http://name5.domain.com:8000/file.dat Could someone help me with that? Any... (10 Replies)
Discussion started by: cootue
10 Replies

6. Shell Programming and Scripting

Help with bash script - Need to get CPU usage as a percentage

I'm writing a bash script to log some selections from a sensors output (core temp, mb temp, etc.) and I would also like to have the current cpu usage as a percentage. I have no idea how to go about getting it in a form that a bash script can use. For example, I would simply look in the output of... (3 Replies)
Discussion started by: graysky
3 Replies

7. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

8. Shell Programming and Scripting

Kill -9 within Bash script kicks out usage info

I have a start|stop|restart script for a custom app we have. After it tries to stop our process the correct way, it checks to see if it's gone, if not it tries to kill it, if that doesn't work kill -9. If I run kill -9 on the PID from the command line it kills it and all is well. If I have the... (1 Reply)
Discussion started by: mglenney
1 Replies

9. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

10. Shell Programming and Scripting

Basic bash 'for loop' usage

Hi! I have a simple question about using a for loop. I'm trying to open up all the zip files in the currect directory with ark, but I am getting the error "bash: syntax error near unexpected token `for $i ; do ark $i ; done ; I looked in the info pages for bash, but I can't seem to figure... (2 Replies)
Discussion started by: Orange Stripes
2 Replies
Login or Register to Ask a Question