awk File pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk File pattern
# 8  
Old 12-18-2009
bash-3.00$ awk 'BEGIN{ORS="\n"} -F"|" '{if ($3/$5 % 10 != 0) {printf "%s,%s|%.7f|%s|%s\n",$1,$2,$3,$4,$5}'
bash: syntax error near unexpected token `('
# 9  
Old 12-18-2009
And this:
Code:
awk -F"|" '{if ($3/$5 % 10 != 0)  {printf "%s,%s|%.7f|%s|%s\n",$1,$2,$3,$4,$5}}' infile > outfile

# 10  
Old 12-18-2009
It does not produces line break after each line

US, dfdsfCL ABX DEC 49.0 BA GOLD CRP|49.0000000| C A DEC 09 48.0 BCK GO CORP| 48.00000000
US, PU 09 49.0 BAK GOLD CORP|49.0000000| T A DEC 09 47.0 BAK GOLD CP| 47.00000000

---------- Post updated at 02:04 PM ---------- Previous update was at 01:58 PM ----------

Also after first word there is , but | after others

---------- Post updated at 02:12 PM ---------- Previous update was at 02:04 PM ----------

Let me explain this properly

ABC|ABC IPO AOP |49.000|ABC IPO AOP|4900.0000
ABC|ABC IOPO AOP |49.000|ABC IOPO AOP|4900.0000

Now I need 5th column to be divided by col 3 and run a modulus $3/$5 % 10 != 0 and then create the file in a with a comma seperated
like this

ABC,ABC IPO AOP ,49.000,ABC IPO AOP,4900.0000
# 11  
Old 12-18-2009
Quote:
Originally Posted by dinjo_jo
bash-3.00$ awk 'BEGIN{ORS="\n"} -F"|" '{if ($3/$5 % 10 != 0) {printf "%s,%s|%.7f|%s|%s\n",$1,$2,$3,$4,$5}'
bash: syntax error near unexpected token `('
Code:
awk -F"|" 'BEGIN{ ORS="\n"  && print "I should read the doc first" }' file


Last edited by ichigo; 12-18-2009 at 04:59 AM..
# 12  
Old 12-18-2009
Can someone help can go through the doc later
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to find pattern in file

Hi I am using awk to find the pattern from the file, but it is not displaying anything. Probably I am missing some syntax in expression. FILE xxxx.Merge.exchMon.BY.qTime 120 read xxxx.Merge.exchMon.BY.qStart 09:55 read... (9 Replies)
Discussion started by: sdosanjh
9 Replies

2. Shell Programming and Scripting

awk remove/grab lines from file with pattern from other file

Sorry for the weird title but i have the following problem. We have several files which have between 10000 and about 500000 lines in them. From these files we want to remove lines which contain a pattern which is located in another file (around 20000 lines, all EAN codes). We also want to get... (28 Replies)
Discussion started by: SDohmen
28 Replies

3. UNIX for Dummies Questions & Answers

awk -remove pattern from file

I have a file like this - I want to remove the 2015 (or any four digit #) from column $4 so I can get: Nov 05 1997 /ifs/inventory2/ for example. Im not sure how. Should I use an if statement with awk? Jan 16 2015 23:45 /ifs/sql_file Jan 16 2015 23:45 /ifs/sql_file Nov 05 2015 1997... (4 Replies)
Discussion started by: newbie2010
4 Replies

4. Shell Programming and Scripting

Big pattern file matching within another pattern file in awk or shell

Hi I need to do a patten match between files . I am new to shell scripting and have come up with this so far. It take 50 seconds to process files of 2mb size . I need to tune this code as file size will be around 50mb and need to save time. Main issue is that I need to search the pattern from... (2 Replies)
Discussion started by: nitin_daharwal
2 Replies

5. Shell Programming and Scripting

awk Pattern Match One File to Another

I want to read from file 1 and pattern match in file two and print field two from the next line. File 1: user1 user2 user3 File 2: name=user1 gud=12345 name=user2 gud=32456 I have this pattern hardcoded but can't work out how to pass file 1 to the pattern match: (6 Replies)
Discussion started by: u20sr
6 Replies

6. Shell Programming and Scripting

awk - writing matching pattern to a new file and deleting it from the current file

Hello , I have comma delimited file with over 20 fileds that i need to do some validations on. I have to check if certain fields are null and then write the line containing the null field into a new file and then delete the line from the current file. Can someone tell me how i could go... (2 Replies)
Discussion started by: goddevil
2 Replies

7. Shell Programming and Scripting

awk get search pattern from a file.

Here Is a problem I am facing with awk. Query --> I want to search for a string in a file and print next 15 lines below the matched string. 1.We do not have GNU grep so cannot use grep -A or grep -B commands. 2. Instead of passing the search pattern as a string to awk. I want the awk to... (4 Replies)
Discussion started by: togotutor
4 Replies

8. Shell Programming and Scripting

Split File by Pattern with File Names in Source File... Awk?

Hi all, I'm pretty new to Shell scripting and I need some help to split a source text file into multiple files. The source has a row with pattern where the file needs to be split, and the pattern row also contains the file name of the destination for that specific piece. Here is an example: ... (2 Replies)
Discussion started by: cul8er
2 Replies

9. Shell Programming and Scripting

AWK match $1 $2 pattern in file 1 to $1 $2 pattern in file2

Hi, I have 2 files that I have modified to basically match each other, however I want to determine what (if any) line in file 1 does not exist in file 2. I need to match column $1 and $2 as a single string in file1 to $1 and $2 in file2 as these two columns create a match. I'm stuck in an AWK... (9 Replies)
Discussion started by: right_coaster
9 Replies

10. Shell Programming and Scripting

How to count the pattern in a file by awk

hello everybody, I have 3 files eg- sample1 sample2 sample3 each file contain word babu many times eg- cat sample1 babu amit msdfmdfkl babu abhi babu ruby amit babu I want to count only the count of babu ,how many times it appeared . (5 Replies)
Discussion started by: abhigrkist
5 Replies
Login or Register to Ask a Question