awk File pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk File pattern
# 1  
Old 12-18-2009
awk File pattern

Code:
cat FILE | awk ORS="\n" -F"|" '{if ($3/$5 % 10 != 0)  {print $0} }' | awk 'BEGIN { ORS="\n" } -F"|" {print $1,$2,$3,$4,$5}' > FILE

The records in FILE are like this
ABC| ABC OPT 23 | 100.000000000000000 | ABC OP 10 | 134.00000000


I need them to be like
ABC,ABC OPT 23|100.0000000|ABC
# 2  
Old 12-18-2009
Hi,

Try this

Code:
cat file | awk -F"|" '
{

print $1","$2"|", substr($3,1,11)"|"substr ($4,1,4)

}' > file1

Cheers,
Vijay.
# 3  
Old 12-18-2009
Code:
(g)awk -F"|" '{split($4,a," "); printf "%s,%s|%.7f|%s" ,$1,$2,$3,a[1]}' file

# 4  
Old 12-18-2009
It shows
ABC,ABC ABC | |

which is not expected the spacing in second and 3rd column is not consistent.
# 5  
Old 12-18-2009
Try this (not tested), presuming you output sample was just the start of the output format:
Code:
awk ORS="\n" -F"|" '{if ($3/$5 % 10 != 0)  {printf "%s,%s|%.7f|%s|%s\n",$1,$2,$3,$4,$5}' infile > outfile

# 6  
Old 12-18-2009
awk: cmd. line:1: ORS=\n
awk: cmd. line:1: ^ backslash not last character on line
# 7  
Old 12-18-2009
Quote:
Originally Posted by dinjo_jo
awk: cmd. line:1: ORS=\n
awk: cmd. line:1: ^ backslash not last character on line
Code:
awk '{....................}' ORS="\n" file

Code:
awk 'BEGIN{ORS="\n"}........' file

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