cut function in linux


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cut function in linux
# 1  
Old 12-28-2011
cut function in linux

hi;
i have file with a lote of data
i would like to cut only numbers that start with prefix 20408

my file contain thousands of rows like this


Code:
,204080700152648,20111215,,,20
31630536259,204080662332510,20
31622520779,204080660098298,20
31651343790,204080130071280,20
31623996541,204080674586050,20
,505023501827190,20111215,204,
31620804392,204080674900896,20
31620929912,204080684300520,20
,228021302213390,20111215,204,
,204086482092214,20111215,262,
31648520081,204080679479548,20

i need only the al number start with prefix 20408


thx

---------- Post updated at 10:51 AM ---------- Previous update was at 10:49 AM ----------

i try this
Code:
cat  filenmae  |cut -d "20408" -f2

but i received this error:
Code:
cut: the delimiter must be a single character

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 12-28-2011 at 11:52 AM.. Reason: code tags, please!
# 2  
Old 12-28-2011
Code:
 nawk -F, '{for(i=1;i<=NF;i++) if ($i ~/^20408/) print $i}' myFile

# 3  
Old 12-28-2011
The awk is probably better, but here is another way: Convert commas to newlines, remove blank lines, look for lines starting with 20408.

Code:
cat filename.txt | tr ',' '\n' | sed -e "/^$/d" | grep \^"20408"

204080700152648
204080662332510
204080660098298
204080130071280
204080674586050
204080674900896
204080684300520
204086482092214
204080679479548

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

Previous Thread | Next Thread

8 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 Dummies Questions & Answers

Function Interposition in Linux

Hello, Please I try to apply the mechanism Interposition Function in Linux on the function write (write a socket) as follows: # include <sys/types.h> # include <sys/socket.h> # include <netinet/in.h> # include <arpa/inet.h> # include <netdb.h> # include <stdio.h> # include <string.h>... (2 Replies)
Discussion started by: chercheur857
2 Replies

3. Programming

[C/Linux]Help in replacing obsolete function

Hi guys, I need help on some function replacement cause I get obsolete function warning(and I must remove it): -gethostbyaddr(arg1,arg2,arg3) -gethostbyname(arg1) -getservbyname(arg1,arg2) can be replaced with getaddrinfo(arg1,arg2,arg3,arg4) but I'm not able to undestand how(libraries... (0 Replies)
Discussion started by: fracche
0 Replies

4. UNIX for Advanced & Expert Users

What is the function to get address of the virtual memory block in linux??

I want address of current virtual memory block? i am using fedora10:wall::wall: (1 Reply)
Discussion started by: powyama
1 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

system() function nd backtrick term in linux

I want to know about the difference between system() function nd backtrick term in linux???? (1 Reply)
Discussion started by: Mac91
1 Replies

7. Shell Programming and Scripting

Need to cut filename in LINUX ksh

Hi, I need to cut filename in Linux ksh. for example file name is c_xxxx_cp_200908175035.zip. I need to get variable with only c_xxxx_cp value. (10 Replies)
Discussion started by: juliyp
10 Replies

8. Shell Programming and Scripting

how to use cut function to obtain this data out in script?

Hi....can you guys help me out in this script?? Below is a text file script....called Bukom.txt and it contains these: BUKOM 20060101 2.5 2.6 2.7 2.8 2.9 2.3 2.1 BUKOM 20060102 2.4 2.5 2.6 2.7 2.7 2.6 2.4 BUKOM 20060103 2.1 2.3 2.5 2.6 2.7 2.7 2.6 Can you guys help... (2 Replies)
Discussion started by: forevercalz
2 Replies
Login or Register to Ask a Question