cut not working the way i want it to


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cut not working the way i want it to
# 1  
Old 01-10-2011
cut not working the way i want it to

Hi Forum

Im having problem with cut it even when i cut a field from an input file
eg
Code:
echo $x | cut -f1 -d':'

it doesnt read the whole line if there is a space in it
eg
thisLineHasA SpaceInIt
Smilie
it only read up to the space.What i want is so the it cut the field as one line
including the space in it.Do i have to change the IFS variable or something
any help would be much appreciated and thank you in advance

Last edited by ShinTec; 01-10-2011 at 02:32 AM..
# 2  
Old 01-10-2011
Double quotes round the variable.

Code:
echo "${x}" | cut -f1 -d':'

# 3  
Old 01-10-2011
I am not sure what output are you looking at, it would be great if you can elaborate a bit. meanwhile try this:

Code:
echo $x | cut -d' ' -f1


Last edited by freakygs; 01-11-2011 at 07:05 AM.. Reason: specifying code
# 4  
Old 01-10-2011
Forget my previous post for the moment (though the code is an improvement it does not fix your problem).
In your script the variable $x does not contain "thisLineHasA SpaceInIt".

Please post the whole script.
# 5  
Old 01-18-2011
sorry for the late post been busy. i want the delimiter to be a colon because the file that im reading in has fields in it that are separated by a colon .When i cut a field from the input file that has a space in it like this eg ("CFSF090898:this 93490394:2323Chi") it only reads the "this" part of the string but does not read the rest of the string. The "93490394" part of the string is ommitted its like it got chopped off and fallen into the abyss why?
forgive me if it doesnt make sense im bad at explaining stuff
# 6  
Old 01-18-2011
I get this:
Code:
$ echo "CFSF090898:this 93490394:2323Chi" | cut -f2 -d':'
this 93490394

What do you get?
# 7  
Old 01-19-2011
the file that i redirect to just has "CFSFO90898:this" but the rest of the line is missing?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 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

Why is my cut command not working ?

OS : RHEL 6.8 Shell : bash I want to remove all lines like below from the history output as it has password. $ history | grep sqlplus 239 sqlplus jn_usr/dxc825#@10.5.12.106/OCSGPD 256 sqlplus osb_soa/KD1egM09@10.5.12.196/BSOAPRD 279 sqlplus jn_usr/dxc825#@10.80.16.219/OCSGPD... (5 Replies)
Discussion started by: John K
5 Replies

3. UNIX for Dummies Questions & Answers

Cut command, no input delim, output delim not working

Hello, I'm using cygwin on my Windows 7 machine. From the man pages of cut: --output-delimiter=STRING use STRING as the output delimiter the default is to use the input delimiter I tried the following commands and got the error messages: $ cut -c1-10,20-30 -d... (10 Replies)
Discussion started by: kojac
10 Replies

4. Shell Programming and Scripting

Cut command not working in for loop

grep -Fxvf testdata.xls file_GTDA1.xls >file_GTDA.xls SLS_COUNT=`grep 'GTDA_Dly_Sls' file_GTDA.xls |wc -l` PMIX_COUNT=`grep 'GTDA_Dly_Pmix' file_GTDA.xls |wc -l` if ; then var1=`cat file_GTDA.xls|grep 'GTDA_Dly_Sls_'` var4="|" for i in $var1... (7 Replies)
Discussion started by: renuk
7 Replies

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

6. Shell Programming and Scripting

why the set rr='echo string|cut not working

I am new to the c shell script, can you let me know why the set rr= is not working. C shell script #! /bin/csh Set tt= 12345_UMR_BH452_3_2.txt set rr='echo $tt | cut –d”_” -f1' syntax error (4 Replies)
Discussion started by: jdsignature88
4 Replies

7. Shell Programming and Scripting

cut the present working directory

how to traverse through each directory (1 Reply)
Discussion started by: Reddy482
1 Replies

8. UNIX for Dummies Questions & Answers

Cut not working in a loop

I have a function "MyPrint" that runs great on a file (BaseData.txt) that has one line of data. If i add rows to the text file it's reading the tFile variable becomes a list of every field 2 in the file. To correct this, i tried to call the function from a loop where i read one line at a time and... (4 Replies)
Discussion started by: KME
4 Replies

9. Solaris

/usr/bin/cut not working with largefiles on Solaris 10

I have a person running a perl script that is parsing > 2G log files and pipes to cut -d " " -f 1,6,7,8... The script itself is in a nfs mounted home directory. It runs fine when started from a solaris 8 box but fails after about 400 lines when started from the solaris 10 box. The solaris... (1 Reply)
Discussion started by: wottie
1 Replies
Login or Register to Ask a Question