Awk text processing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk text processing
# 1  
Old 01-08-2010
Awk text processing

Hi Very much appreciate if somebody could give me a clue ..
I undestand that it could be done with awk but have a limited experience.

I have the following text in the file

1 909 YES NO
2 500 No NO
.
...

1 909 262 647
2 456 234 666
..
....

I need to present it in following form

1 909 YES NO 909 262 647
2 500 No NO 456 234 666

Basically join in one line text for 1,2 etc ...

Thanks in advance
# 2  
Old 01-08-2010
try this.
Code:
 
$ cat fil1
1 909 YES NO
2 500 No NO
 
$ cat fil2
1 909 262 647
2 456 234 666
 
$ join fil1 fil2
1 909 YES NO 909 262 647
2 500 No NO 456 234 666

# 3  
Old 01-08-2010
from the posting i think all the data are in a single file. using join fil1 fil2 is not possible unless you separate it into two different files. But is there an alternative without separating it into different files?
# 4  
Old 01-08-2010
Will this work for you?

Code:
#> cat zam
1 909 YES NO
2 500 No NO



1 909 262 647
2 456 234 666


#> /usr/xpg4/bin/awk '{ x[$1] = x[$1]FS$2FS$3FS$4; } END { for (i in x) {print i x[i]}}' zam
               
2 500 No NO 456 234 666
1 909 YES NO 909 262 647

# 5  
Old 01-09-2010
Code:
awk '{a[$1]=a[$1] FS $2 FS $3 FS $4 } END {for (i in a) {print i, a[i]}}' urfile

Similar solution, ignore my post.Smilie
# 6  
Old 01-10-2010
Thanks a lot - work wonders !!
# 7  
Old 01-12-2010
MySQL

One more Q on above if I may
I have customised , formated a bit above command (may be not perfect but Ok for me) and I wonder if I can print only if $3-$4 >0

cat tmp.lst|grep -v '#'|grep -v '-'|awk '{a[$1]=a[$1] FS $2" "$3" "$4} END {for (i in a) {print i, a[i]}}'\
|awk '{print $1" "$2" "$3" "$4" "$5}' >>tmp1.lst

I know I could have read docs but human nature ... looking for easy ways ..

Thanks again

---------- Post updated at 02:57 PM ---------- Previous update was at 02:42 PM ----------

No worries I figured it out... Smilie
It turned out to be very easy

cat tmp.lst|grep -v '#'|grep -v '-'|awk '{a[$1]=a[$1] FS $2" "$3" "$4} END {for (i in a) {print i, a[i]}}'|awk '{if ($3>$4) print $1" "$2" "$3" "$4" "$5}'

Cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk for text processing

Hi,my file is in this format ", \"symbol\": \"Rbm38\" } ]" I want to convert it to a more user readable format _id pubmed text symbol 67196 18667844 Overexpression of UBE2T in NIH3T3 cells significantly promoted colony formation in mouse cell cultures Ube2t 56190 21764855 ... (3 Replies)
Discussion started by: biofreek
3 Replies

2. Shell Programming and Scripting

Text processing

Hi, Need an advise on $ cat test.txt START field1 field2 field3 field4 field5 field6 END 12345|6|1|2|3|4|111|119 67890|6|1|3|8|9|112|000 $ (4 Replies)
Discussion started by: getmilo
4 Replies

3. Shell Programming and Scripting

Help with text processing

I have an Input file which has a series of lines(which could vary) followed by two blank lines and then another series of lines(Could be any number of lines) followed by two blank lines and then repeats. I need to use filters to convert the following input file(which is an example) to an output... (7 Replies)
Discussion started by: bikerboy
7 Replies

4. Shell Programming and Scripting

Text columns processing using awk

P { margin-bottom: 0.25cm; line-height: 120%; }CODE.cjk { font-family: "WenQuanYi Micro Hei",monospace; }CODE.ctl { font-family: "Lohit Hindi",monospace; }A:link { } I'm trying to build an awk statement to print from a file (file1): A 1,2,3 * A 4,5,6 ** B 1 ... (4 Replies)
Discussion started by: dovah
4 Replies

5. Shell Programming and Scripting

Text processing using awk

I dispose of two tab-delimited files (the first column is the primary key): File 1 (there are multiple rows sharing the same key, I cannot merge them) A 28,29,30,31 A 17,18,19 B 11,13,14,15 B 8,9File 2 (there is one only row beginning with a given key) A 2,8,18,30,31 B ... (3 Replies)
Discussion started by: dovah
3 Replies

6. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

7. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

8. Shell Programming and Scripting

text processing ( sed/awk)

hi.. I have a file having record on in 1 line.... I want every 400 characters in a new line... means in 1st line 1-400 in 2nd line - 401-800 etc pl help. (12 Replies)
Discussion started by: clx
12 Replies

9. UNIX for Dummies Questions & Answers

text file processing

Hello! There is a text file, that contains hierarchy of menues, like: Aaaaa->Bbbbb Aaaaa->Cccc Aaaaa-> {spaces} Ddddd (it means that the full path is Aaaaa->Cccc->Ddddd ) Aaaaa-> {more spaces} Eeeee (it means that the full path is Aaaaa->Cccc->Ddddd->Eeeee ) Fffffff->Ggggg... (1 Reply)
Discussion started by: alias47
1 Replies

10. UNIX for Dummies Questions & Answers

Processing a text file

A file contains one name per line, such as: john doe jack bruce nancy smith sam riley When I 'cat' the file, the white space is treated as a new line. For example list=`(cat /path/to/file.txt)` for items in $list do echo $items done I get: john doe (1 Reply)
Discussion started by: TheCrunge
1 Replies
Login or Register to Ask a Question