awk: Extracting part of the buffer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk: Extracting part of the buffer
# 1  
Old 09-23-2008
awk: Extracting part of the buffer

Hi,

I am trying to extract part of a line using "awk". My requirement is to extract the value $6 (which is the last parameter) from a line. As the sixth value contains some space, i am getting only part of the string. so i am trying to extract from $6 to the end of the buffer.
How to do it using awk?

Plz help.
# 2  
Old 09-23-2008
Quote:
Originally Posted by deepakl28
how to post a query in the forum please reply me asap
Choose the appropriate forum and then click on the New Thread button.
# 3  
Old 09-23-2008
Quote:
Originally Posted by venkat_k
Hi,

I am trying to extract part of a line using "awk". My requirement is to extract the value $6 (which is the last parameter) from a line. As the sixth value contains some space, i am getting only part of the string. so i am trying to extract from $6 to the end of the buffer.
How to do it using awk?
I suppose that you should change the field separator.
If you post a sample data it would be easier.
# 4  
Old 09-23-2008
Here is the data. This is the output of "df" command.

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
35772016 12316720 21608820 37% /
/dev/hda1 101086 13492 82375 15% /boot
tmpfs 451920 0 451920 0% /dev/shm
/dev/sda1 1013284 -7804 1021088 0% /media/LEXAR MEDIA


I have to extract the last field i.e mount point.
In the last line, the mount point has a space. so how to extract "/media/LEXAR MEDIA" from this line?
# 5  
Old 09-23-2008
Instead of using the awk why can;t you use the cut command. pls fidn the below solution for your requirement.

Code:
$ echo "1 2 3 4 5 6 7 8 9"|cut -d" " -f6-

OUTPUT Will be
6 7 8 9
# 6  
Old 09-23-2008
cut -d" " -f6- <your_data_file>

This will display contents from 6th column upto the end of line .
# 7  
Old 09-23-2008
Quote:
Originally Posted by venkat_k
Here is the data. This is the output of "df" command.

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
35772016 12316720 21608820 37% /
/dev/hda1 101086 13492 82375 15% /boot
tmpfs 451920 0 451920 0% /dev/shm
/dev/sda1 1013284 -7804 1021088 0% /media/LEXAR MEDIA


I have to extract the last field i.e mount point.
In the last line, the mount point has a space. so how to extract "/media/LEXAR MEDIA" from this line?
Something like this:

Code:
awk -F'% ' 'NR>1{print $NF}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extracting some part of Perl's Expect Buffer

Hi, I am capturing command's output on remote host using Expect. The problem is that the command line arguments also getting print with the output in file and also need to print last two relevant columns (percentage used and its mounted point). The output of $exp->before() buffer is :df... (1 Reply)
Discussion started by: suneet17
1 Replies

2. Shell Programming and Scripting

Extracting part of data from files

Hi All, I have log files as below. log1.txt <table name="content_analyzer" primary-key="id"> <type="global" /> </table> <table name="content_analyzer2" primary-key="id"> <type="global" /> </table> Time taken: 1.008 seconds ID = gd54321bbvbvbcvb <table name="content_analyzer"... (7 Replies)
Discussion started by: ROCK_PLSQL
7 Replies

3. Shell Programming and Scripting

Extracting the part of string

I have a string: 2015-04-16 07:30:05,625000 +0900 xxxx.com I just want to extract the time from the above line I am using the below syntax x=~ /(.*) (\d+)\:(\d+)\:(\d+),(.*)\.com/ $time = $2 . ':' . $3 . ':' . $4; print $time But it is not working. Can some1 please help (2 Replies)
Discussion started by: karan8810
2 Replies

4. Shell Programming and Scripting

Extracting a part of a string

Hi, I needed to extract some specific characters from a string based on user input. For example: After the script executes the user enters the following details: Please enter the string: This is a shell script Please enter the starting position: 11 Please enter the number of characters to be... (4 Replies)
Discussion started by: ChandanN
4 Replies

5. UNIX for Dummies Questions & Answers

Extracting part of a word

I have the code message={TP=2012:09:23:00:00:00:GMT,SD=2012:09:23:00:00:00:GMT,SP=2,FT=CCGT,FG=3605} I want to extract the FG=3605 parts of this. Please help. I am trying to do this using awk or unix. (5 Replies)
Discussion started by: JenniferTopham
5 Replies

6. Shell Programming and Scripting

Extracting part of line between two words

Hi, I have a file few hundred MB's with text like one below in single line. 20091117 abc xyg 20091117 def ghi 20091118 ppp ttt 20091118 zzz zzz xxx I need to extract part of line from 1st occurence of pattern 20091117 till first occurence of another pattern 20091118. I tried... (3 Replies)
Discussion started by: artistic94555
3 Replies

7. Shell Programming and Scripting

need help extracting this part

JADE TRADER 143W MYPEN 40 HC M X10 28 7 1 0 MYPEN 20 GP X X10 15 2 1 0 MYPEN 40 GP X X10 28 7 1 0 MYPEN 20... (6 Replies)
Discussion started by: finalight
6 Replies

8. Shell Programming and Scripting

Extracting part of a string

Hi all, I have to extract only the second part of a database column (VARCHAR) and the value is seperated by a "~" xyz~ chxyz36r~ abder~000082685 mnops~000083554 fulfil302~00026 Above are some examples of the values and for each record I have to extract the value after "~" , if there is a... (8 Replies)
Discussion started by: sam_78_nyc
8 Replies

9. Shell Programming and Scripting

Extracting part of the basename

Hi, I was wondering if there is an easy way to strip off the required basename. I have a script called apb0110021.sh and the contents of the script are typeset -u MScript=`basename $0 | cut -d. -f1` scriptname=sys.Audit.ksh parms="PROJECT1 dsAudit $MScript 1 BEGIN" $SCRIPTS/$scriptname... (3 Replies)
Discussion started by: madhunk
3 Replies

10. Shell Programming and Scripting

extracting uncommon part between two files

Hi, I need to extract the uncommon (better say incremental) part from 2 files say file_1 and file_2. file_2 contains everything that is in file_1. That is file_2 has been created internally somehow : cat file_1 temp_file > file_2 My objective is to extract the temp_file part from... (2 Replies)
Discussion started by: sabyasm
2 Replies
Login or Register to Ask a Question