|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Help with 'cut'
Hi all,
First post, hope I'm in the right place.. I am trying to modify the following line of a shell: LSTID=`echo $FN | cut -f1 -d' ' | awk -F\. '{print $1}'` What I want to do is set LSTID to the value contained in the first field of a tab delimited file, $FN. Thanks! |
|
#2
|
|||
|
|||
|
$FN is the file name? If that is the case your echo will simply print the name and not the contents of the file.
Code:
$ echo file | cut -f1 file If you are looking to get at the first column, you will have to process that file. Code:
$ seq -s' ' 0 1 10 > file $ seq -s' ' 1 1 11 >> file $ seq -s' ' 2 1 12 >> file $ cat file 0 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 2 3 4 5 6 7 8 9 10 11 12 $ cut -f1 file 0 1 2 $ cut -f1 file | head -n 1 0
__________________
-- I'll provide you with reference points; if they dont work, refer to something else. If you process text, this might make your life a little easier. |
|
#3
|
|||
|
|||
|
I think I got it,
it is returning the file name (it actually originally returned a set of characters from the name, then I started messing around with it), I see that was the original point of the shell so I can use seq to grap the first line of the file and then do cut on that thanks, I'll go give it a try! |
|
#4
|
|||
|
|||
|
Quote:
No. the seq was only to fill the file with some tab separated data. (man seq for more details). It's what I did with the file afterwards that you should look at. Sorry for the misdirection there.... Here are the relevant sections: Code:
$ cut -f1 file 0 1 2 $ cut -f1 file | head -n 1 0 |
|
#5
|
|||
|
|||
|
Just as a passing point, if you just want the first field of first line from file, it is better (more efficient) to do the head first, then the cut.
__________________
"I feel so miserable without you; it's almost like having you here" - Stephen Bishop |
|
#6
|
|||
|
|||
|
just use awk, no need for cut or head
Code:
LSID=`awk 'NR==1{print $1;exit}' file`
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Help with 'cut' |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|