Data handling using AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Data handling using AWK
# 1  
Old 11-03-2010
Java Data handling using AWK

Hi,

I have requirement to fetch lines with a particular character in one column

e.g.
Code:
2.5M  asdsad
3.5M sadsadas
12323M ssdss

i tried following so far
Code:
#echo 2.3M asdsad | nawk -F " " '{print substr($1,length($1))}'
M

So far i have tried following
Code:
 # echo 2.3M asdsad | nawk -F " " '{ if ("print substr($1,length($1))" == "M" ) print $1 $2}'
 # echo 2.3M asdsad | nawk -F " " '{ if ("`print substr($1,length($1))`" == "M" ) print $1 $2}'

 # echo 2.3M asdsad | nawk -F " " '{ if ("substr($1,length($1))" == "M" ) print $1 $2}'

Thanks in advance.

Last edited by Franklin52; 11-03-2010 at 09:19 AM.. Reason: Please use code tags
# 2  
Old 11-03-2010
Quote:
Originally Posted by mtomar
Hi,

I have requirement to fetch lines with a particular character in one column

e.g.
Code:
2.5M  asdsad
3.5M sadsadas
12323M ssdss

i tried following so far
Code:
#echo 2.3M asdsad | nawk -F " " '{print substr($1,length($1))}'
M

Code:
nawk '$1 ~ /M$/' myFile

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 11-03-2010
Something like this,
Code:
awk '/M/' inputfile

This User Gave Thanks to pravin27 For This Post:
# 4  
Old 11-03-2010
Your own code could be corrected as
Code:
echo 2.3M asdsad | nawk '{ if (substr($1,length($1)) == "M" ) print $1 FS $2}'

And do not need to specify the blank-space as field separator (nawk -F " ") as it is the default FS.
or
Code:
nawk '{ if (substr($1,length($1)) == "M" ) print $1 FS $2}' inputfile

This User Gave Thanks to michaelrozar17 For This Post:
# 5  
Old 11-03-2010
Thanks .. both solutions works good for me ..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Handling embedded double quotes within column data

I have a text file where each field is enclosed in double quotes and separated by a comma. But in certain rows we have embedded double quotes within column data For e.g """TRUSPICE CENTRE"" CLAYTON AU" The above value is for a single column but there are embedded quotes within... (2 Replies)
Discussion started by: abhilashnair
2 Replies

2. UNIX for Dummies Questions & Answers

Large file data handling issue

I have a single record large file, semicolon ';' and pipe '|' separated. I am doing a vi on the file. It is throwing an error "File to long" I need to actually remove the last | symbol from this file. sed -e 's/\|*$//' filename is working fine for small files. But not working on this big... (13 Replies)
Discussion started by: Gurkamal83
13 Replies

3. Shell Programming and Scripting

Handling 2 files simultaneously with awk

Hello, Is it possible to handle data from two different files at once in awk (latest version and platform is Fedora). I found on the net that we cannot nest awk. My requirement is that I have two similar files : File 1: Name: abc Val = 58 Name: cdf Val = 1; .................. File... (7 Replies)
Discussion started by: fifteate
7 Replies

4. UNIX for Dummies Questions & Answers

Awk - Handling different types of newlines

Hi. We have some data that's generated from a webpage. Part is pretty well-formatted, but part of it preserves newlines in a way that breaks the record separating in awk. Here's 2 records, filtered through cat -e: Jones,Bob,20,Q: What is your favorite ice cream?$ A: Butter Pecan$ Q: Do you... (6 Replies)
Discussion started by: treesloth
6 Replies

5. Shell Programming and Scripting

handling asterix in AWK

I have a file like below. colA^col2^col3^col4^col5 aa^11^aaa^a1a^111^aa* bb*^22^bbb*^bb2^222^bb cc^33^ccc*^3cc^333^ccc dd^44^d*dd*^d4d^444^ddd ee^55^e*ee^e5e*^555^e*e NOTE: '^' is the field separator. I need to get the output as colA^col2^col3^col4^col5 aa^11^aaa^a1a^111^aa... (5 Replies)
Discussion started by: rinku11
5 Replies

6. UNIX for Advanced & Expert Users

awk function in handling quotes

Hi all, I have input lines like below empno,ename,sal,description ---------------------------- 311,"jone,abc",2000,manager 301,david,200,"president,ac" I need to sum the salary of them i.e. 2000+200 anything suggested Thanks, Shahnaz. Use code tags. (5 Replies)
Discussion started by: shahnazurs
5 Replies

7. Shell Programming and Scripting

handling arrays with awk

Hi, I have an issue that I am trying to resolve using arrays in awk. I have two files, the first one is a dictionary with this format: FILE 1 (dictionary) 'Abrir' 'Open' 'Aceptar' 'Accept' Every line has two fields, a word in two languages. The second file is a simple list of... (3 Replies)
Discussion started by: gmartinez
3 Replies

8. Shell Programming and Scripting

column handling in awk

Dear Scripting experts, I have a problem which i cannot get my head around and wondered if anyone can help me. I have two files "file1" and "file2" and i want to replace column one from file 1 with column one with file2.(where file two has many columns). see example.. ive tried to use cut and... (4 Replies)
Discussion started by: Mish_99
4 Replies

9. UNIX for Dummies Questions & Answers

Realtime data handling between 2 or more systems

Hi I am in need to find a solution the following problem I have more 3 unix based servers. Each handling many different services. Then I have 1 windows based application that needs to collect the .log files in /tmp on the servers. The plan I initially thought of will be to open ftp... (1 Reply)
Discussion started by: ionix
1 Replies

10. Shell Programming and Scripting

AWK handling of single quote

Hi, Can someone let me know how I can acheive the following. I have ~ delimited file and I need to convert into something like SQL insert statements. SrcFile : 1~sjdsdj~asasas~ 2~aaaaa~qwqwqwq~qwq ..... I tried AWK -F"~" '{print "INSERT INTO XX VALUES("$1 " ,\' "$2" \' , \' "$3 }'... (3 Replies)
Discussion started by: braindrain
3 Replies
Login or Register to Ask a Question