help a newb with cut command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help a newb with cut command
# 1  
Old 03-09-2008
Question help a newb with cut command

Ok I'm working on this school assignment and I'm sure there is a simple solution to this but I can't find it anywhere. The scenario is that I have to write a script with a menu and stuff like that. One of the options has to be to generate a sales report from a database called items.dat. Items.dat is just a file with 3 : separated columns. I need to output items.dat as standard output but I need to display column 3 first column 2 second and column 1 last.

I've tried cut -d: -f3,2,1 items.dat but that doesn't work.

Maybe there is a way I could cut each one and then merge it back together?

P.S. it is a bash shell script. and please ask me if something is unclear.

Thanks in advance
# 2  
Old 03-09-2008
please read the man page of cut again. especially the part where it describes how to define fields and ranges.
# 3  
Old 03-09-2008
Quote:
Originally Posted by silveronetrx
I've tried cut -d: -f3,2,1 items.dat but that doesn't work.
I've tried defining fields in the above command however it still displays them in 1,2,3 order even though I have specified 3,2,1.

Maybe you see something I don't... like I said, I'm a bit of a newb at this stuff.

Thanks though for the quick reply
# 4  
Old 03-09-2008
cut doesn't really do what you want,ie display 3rd field first then the rest.
you can use awk
Code:
awk '{print $3,$2,$1}' file

# 5  
Old 03-10-2008
That seems to be exactly what I need. Thanks so much
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

2. Shell Programming and Scripting

CUT command

Team, I want to cut variable string from line and store it in variable. Please help. I/P:- ***Query Completed. 10 rows found. 26 columns returned. So i need this value 10 in my variable. This value may vary from 10 to 1000000 or more. Thanks, Tushar (4 Replies)
Discussion started by: tusharzaware1
4 Replies

3. Shell Programming and Scripting

Cut command

Hi All, I am a beginner learning shell script, Would it be possible to use -c and -f in cut command together ? Example : /opt/oracle/work/Antony/Shell_Script> cat shortlist 2233|a.k. shukula |g.m. |sales2 |12/12/52 |6000 1006|chanchal singhvi ... (3 Replies)
Discussion started by: Antony Ankrose
3 Replies

4. Shell Programming and Scripting

Cut command

hi, i have a file abc,"an,ab",cde,efg abc,anab,cde,efg and need to cut the second field so the output should be abc,cde,efg and i have used cut -d',' -f1-1,3- but its giving me abc,ab",cde,efg abc,cde,efg (4 Replies)
Discussion started by: ATWC
4 Replies

5. UNIX for Dummies Questions & Answers

Cut pid from ps using cut command

hay i am trying to get JUST the PID from the ps command. my command line is: ps -ef | grep "mintty" | cut -d' ' -f2 but i get an empty line. i assume that the delimiter is not just one space character, but can't figure out what should i do in order to do that. i know i can use awk or cut... (8 Replies)
Discussion started by: ran ber
8 Replies

6. UNIX for Dummies Questions & Answers

NEWB Question - BASH COMMAND RESULT for ${0##*/}

This should be extremely simple and someone will probably answer it in .5 seconds. I need to know what: VARIABLE=${0##*/} does? I do not have a shell handy to just try it in. I am reading through some scripts and need to understand this line. Any help is appreciated. Many thanks! -... (3 Replies)
Discussion started by: chrisgoetz
3 Replies

7. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

8. UNIX for Dummies Questions & Answers

Need help with Cut command

Hi I am using 'find' on a particular directory which has some subdirectories too,so when I search for .txt files from the parent directory, it gives all files that matches the pattern in the parent aswellas in the sub directories . eg: Iam at /a/b/c where c has many other directories in it ... (7 Replies)
Discussion started by: jagadish_gaddam
7 Replies

9. UNIX for Dummies Questions & Answers

cut command

i have the following line set line=abc d efg h^ijklmno and then i say: echo $line | cut -d^ -f1 i want to receive this: abc d efg h instead i receive this: abc d efg h how can i ignore blanks in the cut command? (4 Replies)
Discussion started by: tolkki
4 Replies
Login or Register to Ask a Question