Extracting text using cut command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting text using cut command
# 1  
Old 03-19-2012
Extracting text using cut command

Hi All,

I need to extract text 'ULTIMATE and 4spaces after it' from below line
Code:
77"2686"2010-11-21 14:09:13.000"4"I"200"1"2010-11-21 14:09:14.000"001:S087110131     ULTIMATE        4.99   T""

I have used cut command :
Code:
a=`echo $line | cut -f9  -d '"' | cut -c20-31`
echo $a

But this command considers 5 spaces between '087110131 and 'ULTIMATE' as one single character and it does not produce results as required.
And also the number of spaces between the number and the word is not constant all the time,it varies.

Can anyone please help me out.
# 2  
Old 03-19-2012
Try:
Code:
echo "$line" ...

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 03-19-2012
try with sed
Code:
# echo "$line"|sed 's/.*\(ULTIMATE    \).*/\1/'

# 4  
Old 03-19-2012
Thanks Scrutinizer for the fix. I was struggling a lot on this. It was really helpful. Smilie

---------- Post updated at 07:38 PM ---------- Previous update was at 07:34 PM ----------

Hi ygemici,
Its not always ULTIMATE i need to extract. It can be any text from position 20 to 31.
# 5  
Old 03-19-2012
Quote:
Originally Posted by angie1234
Thanks Scrutinizer for the fix. I was struggling a lot on this. It was really helpful. Smilie

---------- Post updated at 07:38 PM ---------- Previous update was at 07:34 PM ----------

Hi ygemici,
Its not always ULTIMATE i need to extract. It can be any text from position 20 to 31.
Code:
# echo "$line"|sed 's#.\{85\}\(.\{12\}\).*#\1#'

# 6  
Old 03-19-2012
Back to cut but with double quotes round string variables to preserve spaces:

Code:
a=`echo "${line}" | cut -c86-97`
echo "${a}"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in extracting data using cut/awk command

Hi Everyone, I have a very simple problem and i am stuck in that from last 8 days. I tried many attempts, googled my query but all in vain. I have a text file named "test.txt" In that suppose i have contents like: Java: 1 Object oriented programming language 2 Concepts of Abstraction... (5 Replies)
Discussion started by: Abhijeet Anand
5 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. 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

4. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

Extracting text from within a section of text using AWK

I have a command which returns the below output. How can I write a script to extract mainhost and secondhost from this output and put it into an array? I may sometimes have more hosts like thirdhost. I am redirecting this output to a variable. So I guess there should be a awk or sed command to... (7 Replies)
Discussion started by: heykiran
7 Replies

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

7. Shell Programming and Scripting

cut command issue from a line of text

Hi, I got a line of text which has spaces in between and it is a long stream of characters. I want to extract the text from certain position. Below is the line and I want to take out 3 characters from 86 to 88 character position. In this line space is also a character. However when using cut... (5 Replies)
Discussion started by: asutoshch
5 Replies

8. Shell Programming and Scripting

Extracting Text

Hi, I have a file like that No seq Text 269091 123443124 how are slkslks, serial no is 042890000 and pincode is 090001223433454 269091 123443124 how are slkslks, Sr/no is 0428901 and 14 digits are is ... (3 Replies)
Discussion started by: krabu
3 Replies

9. Shell Programming and Scripting

Extracting last parsed segment with the cut command

I can see in the man pages how cut can be used to extract a specified string by using the -f qualifier. However, I can't find anywhere how to specify the "last" parsed segment with the cut command. If the string you are parsing is (or can be) differant each time the script is run, but you know... (4 Replies)
Discussion started by: phudgens
4 Replies

10. UNIX for Dummies Questions & Answers

extracting text and reusing the text to rename file

Hi, I have some ps files where I want to ectract/copy a certain number from and use that number to rename the ps file. eg: 'file.ps' contains following text: 14 (09 01 932688 0)t the text can be variable, the only fixed element is the '14 ('. The problem is that the fixed element can appear... (7 Replies)
Discussion started by: JohnDS
7 Replies
Login or Register to Ask a Question