Help with cut statement


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with cut statement
# 1  
Old 05-24-2011
Help with cut statement

Hi i have the below content in a file and i am trying to cut 5.4 , but when i use the below cut command nothing comes up . I am not sure what i am doing wrong. I am new to unix. Please help me, thanks for the help in advance.

Code:
$ cat pid.txt
 5.4 21399 ./PreRating

$ cut -d ' ' -f1 pid.txt

$

OS Used: Linux

Last edited by vbe; 05-24-2011 at 10:11 AM.. Reason: code tags
# 2  
Old 05-24-2011
What is the file type?
Code:
$ file pid.txt


Last edited by vbe; 05-24-2011 at 10:13 AM..
# 3  
Old 05-24-2011
hi pawan,
its in ASCII
Code:
$ file pid.txt
pid.txt: ASCII text


Last edited by vbe; 05-24-2011 at 10:13 AM..
# 4  
Old 05-24-2011
the cut command is working for me as it is
Code:
cut -d ' ' -f1 abc.txt

try using awk
Code:
awk '{print $1}' abc.txt


Last edited by vbe; 05-24-2011 at 10:11 AM..
# 5  
Old 05-24-2011
Strange,Smilie

When i replicate I got the desired result.
Code:
 
-sh-3.00$ cat pid.txt
5.4 21399 ./PreRating
-sh-3.00$ cut -d ' ' -f1  pid.txt
5.4
-sh-3.00$ file pid.txt
pid.txt: ASCII text
 
-sh-3.00$ env
TERM=xterm
SHELL=/bin/sh

I am checking for other possibilities...

---------- Post updated at 08:14 AM ---------- Previous update was at 08:07 AM ----------

what is the output for below command.
Code:
 
$ cut -d ' ' -f1-2 pid.txt


Last edited by pawankt; 05-24-2011 at 10:17 AM.. Reason: code tags please!
# 6  
Old 05-24-2011
Code:
cut -d ' ' -f1-2 pid.txt
 5.4


Last edited by Franklin52; 05-24-2011 at 01:04 PM..
# 7  
Old 05-24-2011
Its seems pid.txt file starting with "space", that it the reason when you are trying with -f1 you are getting empty space,

you should try this below code.(insted of field 1, you should cut field 2)

Code:
$cut -d ' ' -f2  pid.txt

This User Gave Thanks to pawankt For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

6 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. 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

3. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

4. 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

5. Emergency UNIX and Linux Support

Looping using cut statement

i want to create loop for below mentioned A1=`echo $obj1 | cut -d "," -f3` A2=`echo $obj1 | cut -d "," -f4` A3=`echo $obj1 | cut -d "," -f5` A4=`echo $obj1 | cut -d "," -f6` A5=`echo $obj1 | cut -d "," -f7` A6=`echo $obj1 | cut -d "," -f8` A7=`echo $obj1 | cut -d "," -f9` A8=`echo $obj1... (3 Replies)
Discussion started by: pasricha.kunal
3 Replies

6. Shell Programming and Scripting

Iterative statement to cut values from a line

Hi I am new to shell scripting and trying to get values from a text file, I have a text file with values seperated with "|". like aga|120220090525|120220090525|120220090525|120220090530 bab|120220090530|120220090530|120220090535|120220090535|120220090535... (4 Replies)
Discussion started by: mannepalli
4 Replies
Login or Register to Ask a Question